WordPress – How to display featured posts in your theme

“Featured Posts” are a key feature of any news/journal wordpress site. It is pretty easy to develop a wordpress theme to display a fixed number of featured posts from a specific category on the homepage. It can be done using the query_posts() function of wordpress. Here are few lines of code that displays latest 10 posts from the news category , you can edit it to tailor to your needs.

/* Name of your category you want to show posts from */
$cat = "news"; 

/* No. of posts to display*/
$num = "10"; 

	<!-- Show x Posts from $cat category-->
	<?php query_posts('showposts='.$num.'&category_name='.$cat.''); 
	  while (have_posts()) : the_post();
 	<h2><?php the_title(); ?></h2>
	<div class="entry">
     	<?php the_content('Continue...'); ?>
    	<p class="postmetadata">Posted in <?php the_category(', ') ?> | <?php edit_post_link('Edit', '', ' | '); ?>  <?php comments_popup_link('No Comments &#187;', '1 Comment &#187;', '% Comments &#187;'); ?></p>
	<a href="<?php the_permalink(); ?>" class="permalink">Link to this article</a>
<?php endwhile; ?>

The function query_posts(); can be used to control which posts are displayed in the loop. More information on using query_posts(); can be found here : http://codex.wordpress.org/Template_Tags/query_posts .

Here is a list of nonblog wordpress website that can spur your creativity.

One response to this entry

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

2020 All rights reserved | Powered by WordPress
Back to top
Theme by dynamicguru.com