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;">&lt;ul&gt;</span>
<span style="color: #808080;"> &lt;?php $recent = new WP_Query("cat=1&amp;showposts=10"); while($recent-&gt;have_posts()) : $recent-&gt;the_post();?&gt;</span>
<span style="color: #808080;"> &lt;li&gt;&lt;a href="&lt;?php the_permalink() ?&gt;" rel="bookmark"&gt;</span>
<span style="color: #808080;"> &lt;?php the_title(); ?&gt;</span>
<span style="color: #808080;"> &lt;/a&gt;&lt;/li&gt;</span>
<span style="color: #808080;"> &lt;?php endwhile; ?&gt;</span>
<span style="color: #808080;"> &lt;/ul&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
|
|
Save to Delicious with other 0 happy readers
|
