Show all posts in sidebar in single.php
WordPress 4.x
Why does the loop.php
only show the current post in the sidebar when I view a post in single.php
?
I have:
- Post One
- Post Two
- Post Three
If I view “Post One” (single.php), the sidebar only shows “Post One”, if I view the page I have set as the “Blog” page (index.php) in WordPress admin, I see all the posts in the sidebar.
My goal is to have all posts show in the single.php
sidebar. Would be nice to remove the current posts as well! But mostly want to understand the relationship/structure here.
Working with a custom theme based on the HTML5 Blank theme, no major custom functionality.
First WordPress site and this feels like a fundamental structure aspect.
sidebar.php
<aside class="sidebar column" role="complementary">
<?php get_template_part('searchform'); ?>
<?php get_template_part('loop'); ?>
<?php get_template_part('pagination'); ?>
<div class="sidebar-widget">
<?php if(!function_exists('dynamic_sidebar') || !dynamic_sidebar('widget-area-1')) ?>
</div>
<div class="sidebar-widget">
<?php if(!function_exists('dynamic_sidebar') || !dynamic_sidebar('widget-area-2')) ?>
</div>
</aside>
loop.php
<?php if (have_posts()): while (have_posts()) : the_post(); ?>
<article class="loop-template" id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<!-- article content here -->
</article>
<?php endwhile; ?>
<?php else: ?>
<article>
<!-- else content here -->
</article>
<?php endif; ?>
Then in single.php
I am calling <?php get_sidebar(); ?>
outside of any loop or conditional.
Leave an answer