The function get_posts is very useful, and in my opinion under-utilized. It also was incomplete, so I went ahead and completed it.
You can view and use my spanking new functions.php file if you want a complete get_posts.
get_posts is what should be used to get a bunch of posts (or even just one post) outside the wordpress loop (The Loop). It takes 5 arguments :
- numberposts – the number of posts you want returned
- offset – the number of posts you want to skip (like saying skip the first n posts from the results)
- category – the category from which you need these posts
- orderby – order the post by date, or name of any one of the posts table columns
- order – arrange the results in ascending (ASC) or descending (DESC) order
foreach ($posts as $post) :
<li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></li>
<?php endforeach; ?>
will retrieve posts in category 4 sorted by name in ascending order and give you posts 11 through 16, formatted as specified in the code.
If you are using a nightly of v1.3, here’s the diff.
You can sure put get_links to some innovative and interesting use. The FAQ page uses that to display the 5 most recent answers, for example. Other uses could be to pull up the most recent n posts in each category for display in your “menu”, and so on.
Have fun! Now I get back to C++ programming, to solve what seemed like a small problem a week ago. Small problem indeed! I am firing all my neurons and yet there is no perceivable improvement.