3

QUESTION: Is it necessary to include the wordpress loop in page.php? If it is not necessary, why do many themes (including the wordpress 2013 default theme) include it?

I noticed this discussion on the wordpress forums, but I didn't understand the final answer.

furthermore it is stated,

You use The Loop in your template files to show posts to visitors. (Source:http://codex.wordpress.org/The_Loop_in_Action)

BACKGROUND: I am attempting to develop special page templates, and I realized that I don't quite understand what the benefit is of including the loop for pages.php, because after all, pages don't care about posts, that is something that concerns index.php.

2
1

Including Loop is not necessary, but recommended. Also, if you want to use some features you need the loop, for example:

<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php the_content(); ?>
<?php endwhile; endif; ?>
1
  • the_post() should be run inside the while loop. E.g.: <?php if (have_posts()) : while (have_posts() ) : the_post(); ?> Jun 11 '17 at 19:46
1

I think you're also confused by terminology, as the wording in WordPress is a bit, well, confusing.

So all post types, including pages are special types of posts. So "post" can mean the actual usable post type "Post" as well as the general term of all content like "Page" or any other custom post type.

When the Codex says

You use The Loop in your template files to show posts to visitors.

What it actually means is

You use The Loop in your template files to show posts, pages or any other single item of a custom post type to visitors.

Not the answer you're looking for? Browse other questions tagged or ask your own question.