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:

  1. Post One
  2. Post Two
  3. 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.


<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 class="sidebar-widget">
        <?php if(!function_exists('dynamic_sidebar') || !dynamic_sidebar('widget-area-2')) ?>



<?php if (have_posts()): while (have_posts()) : the_post(); ?>

    <article class="loop-template" id="post-<?php the_ID(); ?>" <?php post_class(); ?>>

        <!-- article content here -->


<?php endwhile; ?>

<?php else: ?>


        <!-- else content here -->


<?php endif; ?>

Then in single.php I am calling <?php get_sidebar(); ?> outside of any loop or conditional.

, , , Prestosaurus 3 years 2020-04-06T00:50:57-05:00 0 Answers 74 views 0

Leave an answer