admin管理员组文章数量:1336563
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?
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 Answer
Reset to default 1On 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.
本文标签: Can i forget about the post loop inside the page template
版权声明:本文标题:Can i forget about the post loop inside the page template? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742402814a2468225.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论