submit to reddit

  • Sharebar

Like I promised in a previous post, here is the code required to show latest 5 posts followed by 15 more, like on my homepage. You need to edit the index.php template and add 2 sub-loops separated by wp_reset_query(). Simple as that. Here is the entire index.php code (you should be able to pull the entire loop from there):


<?php get_header();?>
<div id="content">

<br clear="all" /><br />
<?php if(have_posts()) : ?>
 <?php
 query_posts('posts_per_page=5&offset=0');
 while(have_posts()) : the_post();
 ?>
 <div id="post-<?php the_ID();?>" <?php post_class();?>>
 <h2><a href="<?php the_permalink();?>" rel="bookmark" title="Permanent link to <?php the_title();?>"><?php the_title();?></a></h2>
 <small><?php the_time('j F Y');?> by <?php the_author();?></small>
 <div>
 <div style="float:left; margin-right:8px"><?php echo get_the_image_link(array('Thumbnail','My Thumbnail'),'thumbnail');?></div>
 <?php the_excerpt('Read more &raquo;');?>
 </div>
 <div style="clear:both"></div>
 <p>Category: <?php the_category(', ');?> | <?php comments_popup_link('No comments &#187;', '1 comment &#187;', '% comments &#187;');?><br /><?php the_tags(); ?></p>
 </div>
 <?php endwhile;?>

 <?php wp_reset_query();?>

 <h2>More recent articles</h2>
 <br /><br />
 <?php
 query_posts('posts_per_page=15&offset=6');
 while (have_posts()) : the_post();
 ?>
 <div id="post-<?php the_ID();?>" <?php post_class();?>>
 <p>
 <strong><a href="<?php the_permalink();?>" rel="bookmark" title="Permanent link to <?php the_title();?>"><?php the_title();?></a></strong><br />
 <small><?php the_time('j F Y');?> by <?php the_author();?></small>
 </p>
 </div>
 <?php endwhile;?>

 <div>
 <div><?php next_posts_link(__('&laquo; Older Entries','whiskey'));?></div>
 <div><?php previous_posts_link(__('Newer Entries &raquo;','youdrunk'));?></div>
 </div>

 <?php else : ?>
 <h2>Not found</h2>
 <p>No results found.</p>
 <?php endif;?>
</div>
<?php get_sidebar();?>
<?php get_footer();?>

Download index.php here.

You may have noticed that I’m using an unsanitized function, get_the_image_link, to show a thumbnail next to each excerpt. I noticed it when copying the code. Still waiting for a new version of Whiskey Air?

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>