How to Display the most recent post from a specific category in WordPress?
Alright I don’t know if I look like a WordPress Guru or something, but I get questions regarding wordpress alot in the email and often times via Direct Message on my twitter account. Well this was a question that was asked to me in email in response to the new design of Balkhis. How do I display a post from a specific category in wordpress.
Before I tell you how you can do this, I want to share what you can use this for. This can be used to make a custom homepage for your blog. If you want to show your posts on some other pages in the blog from a specific category this is the way you would do it.
Add this code where you want to display the post
<?php
query_posts(‘showposts=1&cat=3′);
while(have_posts()) : the_post();
?>
<ul>
<li><h3><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h3>
<ul><li><?php the_content_limit(520); ?></li>
</ul>
</li>
</ul>
<?php endwhile; ?>
At the top where I say showpost= change the number to how many posts you want to display, and cat=3 is the id of the category, so change the ID of the category to pick which category will you be displaying.
I am using a limit post plugin for wordpress to limit the content. You can download one for yourself also.
Now you can display the most recent post from a specific category





















Hey, I am Syed Balkhi, The guy who is behind Balkhis Inc. I entered the industry back in 2002 not knowing a single thing. I barely spoke English at that time. In the past six years, my language barrier has been eliminated. Aside from English, now I also speak html, and php. Along with the languages I have also managed to master a few arts. Art of web-designing started when I first entered. Messing around with photoshop, I learned how to create my first web design. Now I founded a web designing firm Uzzz Productions. After running numerous amount of websites in various niche, I have mastered the art of web-development. Now I am compiling a resource of what I already know, and what I am learning on this blog. This resource is to help me if I ever need a guide to look back to, and it is help my fellow webmasters.




That would be really useful for showing the different posts in multiple categories in the sidebar, thanks for sharing
This would be useful for making specific windows on the main blog page that have say “latest seo tip” or somthing. Nice tip.
yup yup like I have it on my main page.
Thanks for the tip! I think that using the_excerpt(); would work better than your limit argument. Of course it depends on how big the excerpts are.
well I don’t know about that. You would never know how long you should make your excerpt, so alot of designing issues.
which .php file should i add those code?
wherever you want to display the post….
WOOOT
This is just what I needed. Thank you so much, I can now progress with my project, and not have to use any crazy hacks or plugins!