Skip to content

Instantly share code, notes, and snippets.

@yratof
Created April 30, 2013 20:39
Show Gist options
  • Save yratof/5491765 to your computer and use it in GitHub Desktop.
Save yratof/5491765 to your computer and use it in GitHub Desktop.
Wordpress, 2 loops of one post. Linked together by fate.
<section class="tab-navigation">
<ul class="tabs">
<?php // This is the jquery loop part. it's clever, so look carefully at what happens
wp_reset_query();
$posttype = 'post'; //<------- Change your post type here
// Query whatever you need, for this, i'll be using a custom post type.
$displayposts = new WP_Query();
$displayposts->query('post_type='.$posttype.'&order=asc');
// This will dynamically calculate how many tabs are needed for the posts
while ($displayposts->have_posts()) : $displayposts->the_post();
$tab_number = $displayposts->current_post + 1; ?>
<?php // This is the tab ?><li><a href="#tab<?php echo $tab_number;?>"><?php the_title(); ?></a></li>
<?php endwhile; ?>
</ul>
</section>
<section class="content">
<?php // This calls the Content from the corresponding posts
while ($displayposts->have_posts()) : $displayposts->the_post();
$tab_number = $displayposts->current_post + 1; ?>
<div id="tab<?php echo $tab_number;?>"class="tab_content">
<?php the_post_thumbnail('large');?>
<span class="tab-content-sh"><?php the_content();?></span>
</div>
<?php endwhile; ?>
</section>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment