while reading my usual RSS feeds I stumbled upon this article on displaying your latest post.
It took me eye as I have been busy implementing similar things for my upcoming website, except I have been using WordPress’ WP_Query function to achieve the same results.
Basically WP_Query is used to create a seperate mini-loop outside of your main loop. It has many advantages over using a custom SQL query like
- You don’t need to know proper SQL syntax
- It’s a core WordPress function, so if the database structure changes it will still work
- is more concise and uses less code
- highly customisable in that you can easy modify the post parameters (specify category, author, sort order, etc.)
The below is just a simple demo the grabs a link to the latest post. It shows how easy WP_Query really is to use.
< ?php
$my_query = new WP_Query('showposts=1');
while ($my_query->have_posts()) : $my_query->the_post();
echo '<a href="' . get_permalink() . '">' . the_title('','',FALSE) . '</a>';
endwhile;
?>
1 Comment



























A lady walks into Tiffany’s. She browses around, spots a beautiful diamond bracelet and walks over to inspect it. As she bends over to look more closely she inadvertently breaks wind.