Archives for tag —wordpress theme development tutorial for beginners

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.

<?php
/* 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>
        </div>
<?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 .

© 2010 Dynamic Guru All rights reserved — About UsContactMujtaba