WordPress.org

Ready to get started?Download WordPress

Forums

"Featured posts" on front page? (7 posts)

  1. MikePaulus
    Member
    Posted 4 years ago #

    Hi!

    Just wondering if anyone can think of away to alter this theme so the main page only shows certain content, say a specific category set up for featured posts (as opposed to just the latest).

    Any ideas would be much appreciated -- thanks!

    -mike

  2. kz
    Member
    Posted 4 years ago #

    For example, 123 as the category ID set up for featured posts.

    <?php
    query_posts('posts_per_page=1&cat=123');
    if(have_pots()) :
      the_post();
      ?>
      <div class="featured">
        <a href="<? the_permalink(); ?>"><?php the_title() ?></a>
        <div class="entry"><?php the_content(); ?></div>
      </div>
      <?php
    endif;
    wp_reset_query();
    ?>

    If you want to use category name, change this:
    query_posts('posts_per_page=1&cat=123')

    to this:
    query_posts('posts_per_page=1&category_name=Featured')
    replace [Featured] with your category name.

  3. MikePaulus
    Member
    Posted 4 years ago #

    Hey thanks! I'll give this a try ....

  4. harry2k
    Member
    Posted 4 years ago #

    @kz, thanks for this, I will try this on one of my blog.

  5. Safirul Alredha
    Member
    Posted 4 years ago #

    If not mistaken, since there's no while loop in the code above provided by kz, you don't need to specify posts_per_page=1. Just a simple: query_posts('cat=123');. The query will stop at 1 post.

    And also there's a typo: if(have_pots()) : should be if(have_posts()) :

    Correct me if I'm wrong ;)

  6. iistudios
    Member
    Posted 4 years ago #

    Could someone say where about in the home.php I insert the code as I'm doing trial and error ad getting no where.

    <?php get_header() ?>
    
    	<div id="container">
    	    <div id="content">
    			<div id="nav-above" class="navigation">
    				<div class="nav-previous"><?php next_posts_link(__('<span class="meta-nav">&laquo;</span>', 'sandbox')) ?></div>
    				<div class="nav-next"><?php previous_posts_link(__('<span class="meta-nav">&raquo;</span>', 'sandbox')) ?></div>
    			</div>
    
    <?php while ( have_posts() ) : the_post() ?>
    
    			<div id="post-<?php the_ID() ?>" class="featured <?php sandbox_post_class() ?>">
    				<div class="entry-date bigdate"><abbr class="published" title="<?php the_time('Y-m-d\TH:i:sO') ?>"><?php the_time('d M'); ?></abbr></div>
    				<h2 class="entry-title post-content-title"><a href="<?php the_permalink() ?>" title="<?php printf( __('Permalink to %s', 'sandbox'), the_title_attribute('echo=0') ) ?>" rel="bookmark"><span><?php the_title() ?></span></a></h2>
    				<div class="entry-content post-content">
    					<h4><?php the_title() ?></h4>
    					<p><?php the_excerpt(); ?></p>
    
    				<?php wp_link_pages('before=<div class="page-link">' . __( 'Pages:', 'sandbox' ) . '&after=</div>') ?>
    				</div>
    				<span class="attach-post-image" style="height:300px;display:block;background:url('<?php the_post_image_url('large'); ?>') center center repeat">&nbsp;</span>
    			</div><!-- .post -->
    
    <?php comments_template() ?>
    
    <?php endwhile ?>
    
    			<div id="nav-below" class="navigation">
    				<div class="nav-previous"><?php next_posts_link(__('<span class="meta-nav">&laquo;</span> Older posts', 'sandbox')) ?></div>
    				<div class="nav-next"><?php previous_posts_link(__('Newer posts <span class="meta-nav">&raquo;</span>', 'sandbox')) ?></div>
     			</div>
    
    	  </div><!-- #content -->
    </div>
    	<!-- #container -->
    <?php get_footer() ?>
  7. iistudios
    Member
    Posted 4 years ago #

    I managed to sort it out by trial and error

    line <?php while ( have_posts() ) : the_post() ?>

    insert query_posts('posts_per_page=4&category_name=your_cat'); just prior to while ( have_posts() ) : the_post() ?>

    works a treat now, another job off my list.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags