• My page content is being displayed in my sidebar instead of my posts. I am new to wordpress, so I apologize if the answer is simple. I have my front page set to “home” and my posts page set to news. On the news page the posts show up in the sidebar, but I imagine that is because the posts are the content of this page. I am creating my own theme, but working off of a Starker’s 2.0 theme.

    Here is my sidebar.php code:

    <?php ?>
    
    			<ul id="sidebar">
    
    <?php if ( ! dynamic_sidebar( 'primary-widget-area' ) ) : ?>
    
                <li class="widget">
    				<h2>Recent News</h2>
                                <ul>
                           			<?php if(have_posts()) : while(have_posts()) : the_post(); ?>
                                    <li><a href="<?php the_permalink(); ?>">
                                    	<h3><?php the_title(); ?></h3>
                                        <p class="meta"><?php the_date(); ?></p>
                                        <?php the_content('Read More...'); ?></a>
                                     </li>
                                     <?php endwhile; ?>
                                <?php else : ?>
                                	<p> Nada </p>
                                <?php endif; ?>
                                     <h2><a href="#">Lea Mas >></a></h2>
    
                                </ul>
    			</li>
    
    		<?php endif; // end primary widget area ?>
    			</ul>
    
    <?php
    	// A second sidebar for widgets, just because.
    	if ( is_active_sidebar( 'secondary-widget-area' ) ) : ?>
    
    			<ul class="xoxo">
    				<?php dynamic_sidebar( 'secondary-widget-area' ); ?>
    			</ul>
    
    <?php endif; ?>

    Let me know if you know how to fix this issue. I can’t seem to find information online about when the loop calls page content and in what circumstances it calls post content.
    Thanks,
    Sean

Viewing 3 replies - 1 through 3 (of 3 total)
  • Well, your code has the loop outputting the content in the sidebar so that’s why it’s showing up there.

    The loop should be being called in whatever template you are using to output the content of your blog. What file that might be will depend on the code design decisions you’ve made. For example, you might have a loop.php file like twentyten does or you might have many separate templates with loops in them like twentyeleven does IIRC.

    Since you’re creating your own theme, only you will know how you’re doing that. But you definitely shouln’t be outputting the content in sidebar.php – unless there’s some sublety I’m missing.

    HTH

    PAE

    Thread Starter seansean11

    (@seansean11)

    Thanks Peredur, but I still don’t understand why sometimes the loop calls the posts and sometimes it calls the page info. There has to be an explaination for this. I have changed up a lot of things on my template and now it is pulling my posts just like I wanted. I can’t seem to figure out why though. Here is my new code: `<?php ?>

    <?php if ( ! dynamic_sidebar( ‘primary-widget-area’ ) ) : ?>
    <ul class=”xoxo”>
    <?php dynamic_sidebar( ‘primary-widget-area’ ); ?>
    </ul>

    <li id=”crumbsnav”>

    </li>
    <li class=”widget”>
    <h2>Últimas Noticias</h2>
    <ul>
    <?php query_posts($query_string . ‘&showposts=5’); if(have_posts()) : while(have_posts()) : the_post(); ?>
    <li><a href=”<?php the_permalink(); ?>”>
    <h3><?php the_title(); ?></h3>
    <p class=”meta”><?php the_date(); ?></p>
    <?php the_content(‘Read More…’); ?></a>
    </li>

    <?php endwhile; ?>
    <?php else : ?>
    <p> Nada </p>
    <?php endif; ?>
    <h2 class=”readmore”><a href=”#”>Read More >></a></h2>
    </ul>

    </li> <!–end widget–>
    <?php endif; ?>
    </ul><!– end secondary –>`
    Basically what I’m trying to do is make my own recent post widgets, because I just can’t seem to find a plug-in that is easy to fit to my original css (I designed the site in HTML and CSS first) and offers the features that I want. Maybe you can shed some light as to why this now works and if this is standard practice when you need to have custom widgets in your sidebar. And, thank you very much for helping me with this novice post. Sometimes it’s difficult to get a response in the forum.

    The answer to your first question is that WordPress uses the Template Hierarchy to determine what template to use. It then executes the query in that template. At the end of the day, all WP is doing is using the data in the query string to query the database via the WP_Query object, if I understand matters correctly.

    In the case of a page (or a single post) the loop just returns a single item.

    So, for instance, if your theme was organised like the twentyten theme, WP would call the loop-page.php template.

    As to making a recent posts widget, you would use something like wp_get_archives() I believe.

    HTH

    PAE

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Page Content In Sidebar Instead of Post Content’ is closed to new replies.