WordPress.org

Ready to get started?Download WordPress

Forums

Codex tea leaves. 2011 theme. (4 posts)

  1. sepoto
    Member
    Posted 3 years ago #

    //page.php
    <?php get_header(); ?>
    <div id="primary">

    <div id="content" role="main">
    <?php the_post(); ?>
    <?php get_template_part( 'content', 'page' ); ?>
    <?php comments_template( '', true ); ?>
    </div><!-- #content -->

    </div><!-- #primary -->
    <?php get_footer(); ?>

    With regards to the call to the_post();.. Why do I need to iterate for the loop on a page that is not supposed to really be using any posts? With regards to get_template_part... Can you really get part of the page template from page.php? Where is 'content' defined? Where is the code located that is fetched by get_template_part above? Those are my questions for the time being.

    Thank you!

  2. Srijan Mitra
    Member
    Posted 2 years ago #

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

    This section is defined your content. You don't need to post individually <?php the_post(); ?>.

    Else you can do one thing ... just remove ...
    <?php get_template_part( 'content', 'page' ); ?>

    ... And instead of that just paste there .....

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

    <h2><?php the_title(); ?></h2>
    <p><?php the_content();?></p>

    <?php endwhile; ?>

    And the_post() is different its located at wp-includes/query.php.

    So good luck.

  3. Digital Raindrops
    Member
    Posted 2 years ago #

    With regards to the call to the_post();.. Why do I need to iterate for the loop on a page that is not supposed to really be using any posts?

    Posts, pages, custom posts, and image details are all stored in the same table (wp-post) and a query or filter is created to return a dataset, either a single page or a set of posts, it is normal for database queries to work like this!, as there is only one page (wp-post) in the filter the loop is used to find the first, in posts it finds the first then next until the end of the dataset.

    With regards to get_template_part... Can you really get part of the page template from page.php? Where is 'content' defined?

    Template parts are blocks of code that you want included in the template, it is an advanced wrapper for the include statement, it takes two arguments, so get_template_part('content','category') first looks for a file called content-category.php, if it can not find the file then content.php.

    Where is the code located that is fetched by get_template_part above? Those are my questions for the time being.

    Have a look in the twenty eleven theme at all the files starting "content-", like content-page.php used in the page.php template.

    HTH

    David

  4. Digital Raindrops
    Member
    Posted 2 years ago #

    @Srijan Mitra
    Why are you answering topics nine months later, I have just wasted time replying to this topics, which was likely resolved months ago!

    David :(

Topic Closed

This topic has been closed to new replies.

About this Topic