Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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:

<html>
<head>
    <title>Lorem ipsum</title>
</head>
    <body>
    <div id="sidebar">
        <section>
            <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 -->               
        <nav>
            <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>
    <div id="content">
        <article id="post-<?php the_ID(); ?>" class="post" role="main">
            <header>
                <p class="post-date"><time datetime="2009-09-04"><?php the_time('F jS, Y') ?></time></p>
                <h1>
                    <?php the_title(); ?>
                </h1>
            </header>
            <?php the_content(); ?> 
        </article> <!-- post -->

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

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

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?

share|improve this question

2 Answers 2

up vote 0 down vote accepted

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.

share|improve this answer
    
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/… –  Donald Jenkins Mar 8 '11 at 22:58
    
[SOLVED] I solved it by moving rewind posts from the second to the first loop. The page works now. –  Donald Jenkins Mar 8 '11 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

share|improve this answer
    
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. –  Donald Jenkins Mar 8 '11 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. –  Donald Jenkins Mar 8 '11 at 23:26

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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