• 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

Viewing 6 replies - 1 through 6 (of 6 total)
  • 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.

    Thread Starter mikepaulus

    (@mikepaulus)

    Hey thanks! I’ll give this a try ….

    harry2k

    (@harry2k)

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

    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 😉

    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() ?>

    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.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘“Featured posts” on front page?’ is closed to new replies.