0

A simple page.php template often looks like this:

<?php
/**
 * The template for displaying all pages
 *
 * This is the template that displays all pages by default.
 * Please note that this is the WordPress construct of pages
 * and that other 'pages' on your WordPress site will use a
 * different template.
 *
 * @package WordPress
 * @subpackage Twenty_Twelve
 * @since Twenty Twelve 1.0
 */
get_header(); ?>

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

      <?php while ( have_posts() ) : the_post(); ?>
        <?php get_template_part( 'content', 'page' ); ?>
        <?php comments_template( ’, true ); ?>
      <?php endwhile; // end of the loop. ?>

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

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

So there is a while loop for post's inside.

But I do not have several "pages" rendered out in any case. Is what assume!

E.g. for archive's this loop makes totally sense.


Now to my question

I would like to structure the template like the following example:

<?php get_header(); ?>

<?php while ( have_posts() ) : the_post(); ?>
  <?php a_special_content_output_before_the_main_container(get_title()); ?>

  <div id="primary" class="site-content">
    <div id="content" role="main">
        <?php get_template_part( 'content', 'page' ); ?>
        <?php comments_template( ’, true ); ?>
    </div><!-- #content -->
  </div><!-- #primary -->
<?php endwhile; // end of the loop. ?>

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

This would mean if this while loop has two items inside I will get invalid markup, because of duplicated id selectors.

Is there a situation a page can have several entries. Means that have_posts() is bigger 1?

1

On single page and post templates the main loop is only ever going to contain one post, so you don't need to worry about duplicate IDs in your example.

| improve this answer | |
  • so this is just a WordPress historical thingy behaviour. because pages are stored as post's in general, i guess. – André Kelling May 25 at 14:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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