Ready to get started?Download WordPress


TwentyThirteen calling content.php from index.php but not from page.php (2 posts)

  1. physoc
    Posted 11 months ago #

    I was hoping someone could explain why TwentyThirteen calls content.php from index.php whereas page.php contains the loop? Also, why does index.php call content.php if there is no content to display:

    <?php if ( have_posts() ) : ?>
    			<?php /* The loop */ ?>
    			<?php while ( have_posts() ) : the_post(); ?>
    				<?php get_template_part( 'content', get_post_format() ); ?>
    			<?php endwhile; ?>
    			<?php twentythirteen_paging_nav(); ?>
    		<?php else : ?>
    			<?php get_template_part( 'content', 'none' ); ?>
    		<?php endif; ?>

    Thanks :)

  2. Konstantin Obenland
    Theme Wrangler
    Posted 11 months ago #

    Hi physoc,

    page.php contains the loop, because there is no other place in Twenty Thirteen where this piece of code would get reused.

    If there is no content to display, index.php calls actually content-none.php. get_template_part()goes through a progression and looks for a file that is called like the combination of the two arguments, first in a possible child theme and then in the parent theme. If that file does not exist, it will look for a file that is called like the first argument. In our case it checks for the files like this:


    If there is content to display, we'd ask get_template_part() to look for a file that is called like the current post format (e.g. content-aside.php), and if it is not there serve content.php.


You must log in to post.

About this Topic