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;
?>




























Yeah! Finally i understand what you mean. It seems much simpler than what i had done. Thanks Alex!
It’s ok to have a comment.
Welcome!
Will there be any update on this post BTW? I have added your feed to my reader.
You got that right, sister!
This is very useful news, cheers. I was doing my head in trying to learn SQL syntax!
THanks For the information !!
Thanks?it’s useful?
Thanks for you help!