Balkhis - Vision For Success

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



To stay updated with the blog, please consider subscribing to my full feed RSS. You can also subscribe by Email and have new posts sent directly to your inbox. I hate spam as well, so I promise you that you will not be spammed.
Add to Social Bookmarks:
Add this Article to Digg Add this Article to Stumbleupon Add this Article to Del.icio.us Add this Article to Reddit Add this Article to Newsvine Add this Article to Technorati

RSS feed | Trackback URI

7 Comments »

Comment by Rajaie AlKorani
2008-07-17 13:20:50

That would be really useful for showing the different posts in multiple categories in the sidebar, thanks for sharing :)


 
Comment by Authority Directory
2008-07-17 20:10:18

This would be useful for making specific windows on the main blog page that have say “latest seo tip” or somthing. Nice tip.


Comment by Syed Balkhi
2008-07-17 20:16:29

yup yup like I have it on my main page.


 
 
Comment by Corey Freeman
2008-08-18 14:29:55

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.


Comment by Syed Balkhi
2008-08-18 16:40:39

well I don’t know about that. You would never know how long you should make your excerpt, so alot of designing issues.


 
 
Comment by asura
2008-10-07 11:04:56

which .php file should i add those code?


Comment by Syed Balkhi
2008-10-07 15:22:30

wherever you want to display the post….


 
 
Name (required)
E-mail (required - never shown publicly)
URI
Your Comment (smaller size | larger size)
You may use <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> in your comment.