I'm having problems setting up a single WordPress template page to display post data outside of the Loop. The page has a left sidebar in which I want to display post meta data, tags and navigation links to previous and next posts, followed by a main column with the post title and content:

    <title>Lorem ipsum</title>
    <div id="sidebar">
            <p>The post on this page is a <?php if (in_category('apples')) { ?> <a href="http://mydomain.com/category/apples/" rel="nofollow">apples</a> blog post.  <?php } else { ?> <a href="mydomain.com/category/pears/" rel="nofollow">pears</a> blog post. <?php }; ?>.  You can browse the <a href="http://mydomain.com/archives/" rel="nofollow">Archives</a> to find more articles of this type.</p>
        </section> <!-- post-metadata -->               
            <h2 class="sidebar-title">Previous</h2>
                <ul><li><?php previous_post_link('<strong>%link</strong>'); ?></a></li></ul>
            <h2 class="sidebar-title">Next</h2>
                <ul><li><?php next_post_link('<strong>%link</strong>'); ?></a></li></ul>
        </nav>  <!-- post-navigation -->
    <div id="content">
        <article id="post-<?php the_ID(); ?>" class="post" role="main">
                <p class="post-date"><time datetime="2009-09-04"><?php the_time('F jS, Y') ?></time></p>
                    <?php the_title(); ?>
            <?php the_content(); ?> 
        </article> <!-- post -->

        <section id="comments">
            <?php comments_template( '', true ); ?>
        </section>  <!-- comments -->

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

The way I'm trying to solve the issue is by running a separate loop in the sidebar (sidebar-single.php), rewinding and then running it again in the contents section (single.php).

Unfortunately, while the data from the first loop is diplaying correctly in the sidebar, the loop doesn't rewind for some reason and as a result the content for the next post displays in the content part of the page. See an example here.

Any ideas as to how the non-rewinding issue in this setup can be fixed, or alternatively how the objective can be attained by other means?

2 Answers 2


did you call rewind posts?

I've done something similar on a site and used css to solve. The site uses 960 grid (960.gs), which comes packaged with "push" and "pull" classes that let you rearrange content relative to its position in the markup. In our case, the sidebar content is coming from a sidebar template and is called after the main content. We use the css classes to push the main section to the right alignment and pull the sidebar to the left alignment.

  • Thanks. I tried doing that, and it works, kind of. But I wanted a solution that wasn't a hack. I'm using rewind posts, but the problem is they're not rewinding. The link to the page with the code is here: beta.donaldjenkins.net/2011/02/… Commented Mar 8, 2011 at 22:58
  • [SOLVED] I solved it by moving rewind posts from the second to the first loop. The page works now. Commented Mar 8, 2011 at 23:25

What you really need to show us is the relevant code from your sidebar-single.php. But at as guess, how are you rewinding? If you aren't using wp_reset_query(), you might want to try that. http://codex.wordpress.org/Function_Reference/wp_reset_query

  • I'm actually opening two separate loops and rewinding the first loop before starting the second: see this page for the code and resultant display; as you can see, the sidebar lists data for one post and, despite the rewind, the main content section skips to the next post. Can't work out why. Commented Mar 8, 2011 at 23:00
  • [SOLVED] I moved the rewind from the beginning of the second loop to the start of the first, and that did the trick. Commented Mar 8, 2011 at 23:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.