Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP


the loop on single.php and page.php appears unnecessary. #301

drrobotnik opened this Issue · 6 comments

4 participants


Is it for consistency that we include a while conditional around the loop on single/page.php?

If there is no post than they'd be redirected to the 404.php so to me it seems unnecessary. Also on a single/page there shouldn't be instances of more than one post without a custom query. I'd change this to an if conditional or remove it entirely like so:

 * The Template for displaying all single posts.
 * @package _s

get_header(); the_post(); ?>

    <div id="primary" class="content-area">
        <main id="main" class="site-main" role="main">

            <?php get_template_part( 'content', 'single' ); ?>

            <?php _s_content_nav( 'nav-below' ); ?>

                // If comments are open or we have at least one comment, load up the comment template
                if ( comments_open() || '0' != get_comments_number() )

        </main><!-- #main -->
    </div><!-- #primary -->

<?php get_sidebar(); ?>
<?php get_footer(); ?>

Curious on the thought behind the current decision before I submitted a PR.


have_posts is useful for more than just a conditional check—per the codex:

As a side effect, have_posts starts, steps through, or resets The Loop. At the end of the loop, have_posts returns 0 after calling rewind_posts.


Hmm, looking at the code behind have_posts, it's actually a fairly straightforward function... I'd say there's value in consistency, though.


I'm always in favor of removing code where it makes sense. Looking at have_posts(), and the lack of an else statement in the template make me wonder if this could be one of those cases.


I prefer to use the standard Loop in all singular templates in _s. The code suggested above is what we refer to as a "partial loop" and really causes issues in other queries on the page. Historically this has appeared in a couple of the Default themes and has been fixed right away. Please see the following ticket:


Sweet, thanks for the heads up @mfields!

@obenland obenland closed this

No Problem!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.