17May2009

Display latest post from specific category

This is a very useful hack for WordPress Theme Developers and coders, because while developing most of Wp cms themes add this hack in their cms template. So now i’ll explain how to display Recent post from specific category. Make sure that you made the back up of your theme files.

So move to the main part, Add the below code to display the Recent posts from specific categories.

<span style="color: #808080;">&amp;lt;ul&amp;gt;</span>

<span style="color: #808080;"> &amp;lt;?php $recent = new WP_Query("cat=1&amp;amp;showposts=10"); while($recent-&amp;gt;have_posts()) : $recent-&amp;gt;the_post();?&amp;gt;</span>

<span style="color: #808080;"> &amp;lt;li&amp;gt;&amp;lt;a href="&amp;lt;?php the_permalink() ?&amp;gt;" rel="bookmark"&amp;gt;</span>

<span style="color: #808080;"> &amp;lt;?php the_title(); ?&amp;gt;</span>

<span style="color: #808080;"> &amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;</span>

<span style="color: #808080;"> &amp;lt;?php endwhile; ?&amp;gt;</span>

<span style="color: #808080;"> &amp;lt;/ul&amp;gt;</span>

For example, If you want to show related post from tech, then edit cat=1 with the tech category id. To display more then or less then 5 post, then find showposts=5 and edit the number in it.
I hope you understand, If you have some difficulties with this code, then write them as comments.

Related Posts

Sharing is caring.
  • Subscribe to our feed
  • Share this post on Delicious
  • StumbleUpon this post
  • Share this post on Digg
  • Tweet about this post
  • Share this post on Mixx
  • Share this post on Technorati
  • Share this post on Facebook
  • Share this post on NewsVine
  • Share this post on Reddit
  • Share this post on Google
  • Share this post on LinkedIn

Discussion

No responses to "Display latest post from specific category"

There are no comments yet, add one below.

Leave a Comment