WordPress Code Snippets

A fresh mix of code snippets and tutorials

Triple Loop Navigation

37

Never thought this was possible, and still don’t know for sure because I haven’t had time to test this code sample found in a pastebin. Included here in its entirety for reference.

<?php get_header(); ?>

<div id="content">

<!-- **********************Loop 1********************** -->
<div id="featured_post">
<?php
    $recentPosts = new WP_Query();
    $recentPosts->query('showposts=1'.'&paged='.$paged);
?>
<?php while ($recentPosts->have_posts()) : $recentPosts->the_post(); ?>
    <div class="post">
<div class="post_category">In <?php if (the_category(' &amp; '))  the_category(); ?></div>
<h2 class="post_title"><a href="<?php the_permalink(); ?>" id="post-<?php the_ID(); ?>" title="<?php the_title_attribute(); ?>" rel="bookmark"><?php the_title(); ?></a></h2>
<div id="post_byline">
<p class="post_author">By <?php the_author_posts_link(); ?></p>
<p class="post_dateline"><?php the_time('l, F j, Y'); ?></p>
</div>
<div class="post_content"><?php the_content(); ?></div>
<div class="post_meta">
<p class="post_info">Tags: <?php if (get_the_tags()) the_tags('',', ',''); ?></p>
<p class="post_info"><?php comments_popup_link('No Comments', '1 Comment', '% Comments'); ?><span class="post_edit"><?php edit_post_link('&nbsp;&#124;&nbsp;Edit', '', ''); ?></span></p>
</div>
</div><!-- end post -->

<?php endwhile; ?>

</div>


<!-- **********************Loop 2********************** -->
<div id="odd_post">
<?php $postcount = 1; rewind_posts(); ?>
<?php if (have_posts()) : ?>
<?php while(have_posts()) : ?>
<?php
$postcount++;
if( ($postcount % 2) == 0 ) : // skip 'even' posts
$wp_query->next_post();
else :
?>
<?php the_post(); ?>
<div class="post">
<div class="post_category">In <?php if (the_category(' &amp; '))  the_category(); ?></div>
<h2 class="post_title"><a href="<?php the_permalink(); ?>" id="post-<?php the_ID(); ?>" title="<?php the_title_attribute(); ?>" rel="bookmark"><?php the_title(); ?></a></h2>
<div id="post_byline">
<p class="post_author">By <?php the_author_posts_link(); ?></p>
<p class="post_dateline"><?php the_time('l, F j, Y'); ?></p>
</div>
<div class="post_content"><?php the_excerpt(); ?></div>
<div class="post_meta">
<p class="post_info">Tags: <?php if (get_the_tags()) the_tags('',', ',''); ?></p>
<p class="post_info"><?php comments_popup_link('No Comments', '1 Comment', '% Comments'); ?><span class="post_edit"><?php edit_post_link('&nbsp;&#124;&nbsp;Edit', '', ''); ?></span></p></div>
</div><!-- end post -->
<?php endif; ?>
<?php endwhile; ?>
<?php endif; ?>
</div>

<!-- **********************Loop 3********************** -->
<div id="even_post">
<?php $postcount = 2; rewind_posts(); ?>
<?php query_posts('showposts=0&offset=1'.'&paged='.$paged); ?>
<?php if (have_posts()) : ?>
<?php while(have_posts()) : ?>
<?php
$postcount++;
if( ($postcount % 2) != 0 ) : // skip 'odd' posts
$wp_query->next_post('showposts'.'&paged='.$paged);
else :
?>
<?php the_post();  ?>
<div class="post">
<div class="post_category">In <?php if (the_category(' &amp; '))  the_category(); ?></div>
<h2 class="post_title"><a href="<?php the_permalink(); ?>" id="post-<?php the_ID(); ?>" title="<?php the_title_attribute(); ?>" rel="bookmark"><?php the_title(); ?></a></h2>
<div id="post_byline">
<p class="post_author">By <?php the_author_posts_link(); ?></p>
<p class="post_dateline"><?php the_time('l, F j, Y'); ?></p>
</div>
<div class="post_content"><?php the_excerpt(); ?></div>
<div class="post_meta">
<p class="post_info">Tags: <?php if (get_the_tags()) the_tags('',', ',''); ?></p>
<p class="post_info"><?php comments_popup_link('No Comments', '1 Comment', '% Comments'); ?><span class="post_edit"><?php edit_post_link('&nbsp;&#124;&nbsp;Edit', '', ''); ?></span></p>
</div>
</div><!-- end post -->
<?php endif; ?>
<?php endwhile; ?>
<?php endif; ?>
</div>


<div id="next_links">
<p class="next_post"><?php next_posts_link('Older entries') ?></p><p class="previous_post"><?php previous_posts_link('New Entries') ?></p>
</div>

</div><!-- end content -->

<?php get_footer(); ?>

Learn more

WordPress Themes In Depth


Show Support

Like our new Facebook Page to show support!