WordPress.org

Ready to get started?Download WordPress

Forums

How to: display a single "featured" post on top of blog page. (1 post)

  1. cmegown
    Member
    Posted 2 years ago #

    Hey folks, I've decided to write this brief post with an easy-to-understand explanation of how to get a single "featured" type of post to show on the front blog page only. I'm writing this because I was trying to figure out the easiest way to implement a "featured" post without too much code and especially without a plugin.

    *Note: The "featured" post in this example is simply a normal post under a Featured category. What I came up with is something like this:

    <?php if (is_home() && !is_paged()) : ?>
    
        <?php query_posts('cat=13&showposts=1'); // shows only one single Featured post ?>
        <?php while (have_posts()) : the_post(); ?>
    
            <div class="sticky" id="post-<?php the_ID(); ?>">
    
                <h2>"><?php the_title(); ?></h2>
    
                <?php include('meta.php'); ?>
    
                <div class="entry">
    
                    <?php the_excerpt(); ?>
    
                    <div class="after-excerpt">
                        <?php if (has_tag()) { ?>
                            <div class="tags">
                                <img src="<?php bloginfo('template_url'); ?>/images/tag.jpg" alt="Tagged as:" />
                                <?php the_tags('', ', ', ''); ?>
                            </div>
                        <?php } ?>
    
                        <div class="read-more-link">Read More ยป</div>
                        <br style="clear: both" />
                  </div>
    
              </div>
    
          </div>
    <?php endwhile; ?>
    
    <?php endif; wp_reset_query(); ?>
    <?php query_posts('cat=-13'); // excludes Featured posts ?>
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    <!-- do the rest of your normal post stuff here -->

Topic Closed

This topic has been closed to new replies.

About this Topic

  • RSS feed for this topic
  • Started 2 years ago by cmegown
  • This topic is not a support question
  • WordPress version: 3.3