logo
Ask your WordPress questions! Pay money and get answers fast! (more info)

Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

If the asker does not get an answer then they have 10 days to request a refund.

$5
Adding the blog page content after the loop

Hello,

I am looking to retrieve the content from the page that has been defined as "the posts page" in the wordpress back end. My index.php looks like this:


get_header(); ?>
<section id="main">
<?php
get_template_part( 'loop', 'index' );
the_content();
if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
echo "<section class='featuredimage'>";
the_post_thumbnail("full");
echo "</section>";
}
?>
</section><!-- #main -->
<?php get_footer(); ?>


This will execute the loop and generate the posts, which is good, but when the loop is complete I would like to display the actual content of the blog page itself (in other words: the content that has been typed into the text field in the back end). For some reason, I am unable to reset the wp-query and retrieve any of the actual page data.

The above code loops through the posts using loop.php, but instead of giving me the Blog page's post content and feature image, it provides the undesirable result of displaying the content from the very first post, again.

Thanks in advance to anyone who can help resolve this, it is much appreciated!

Cheers,
Matt



This question has been answered.

Cartogram | 02/13/11 at 9:32pm Edit


The experts have suggested, on average, a prize of $15 for this question.

(4) Possible Answers Submitted...

See a chronological view of answers?

Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

  • avatar
    Last edited:
    02/13/11
    9:57pm
    Chris Lee says:

    You should try putting your code in the loop or supplying a seperate wp_query

  • avatar
    Last edited:
    02/13/11
    10:08pm
    Roberto Mas says:

    or something like this should work


    get_header(); ?>
    <?php get_sidebar(left); ?>
    <div id="container">
    <div id="content" class="weAreEquals" role="main">

    <?php
    /* Run the loop to output the posts.
    * If you want to overload this in a child theme then include a file
    * called loop-index.php and that will be used instead.
    */
    get_template_part( 'loop', 'index' );
    ?>


    <?php query_posts('post_type=post&showposts=1'); ?>
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    <article>
    <?php the_title(); ?>
    <?php the_post_thumbnail(); ?>
    <?php the_content(); ?>
    </article>
    <?php endwhile; else: ?>
    <?php endif; wp_reset_query(); ?>
    </div><!-- #content -->
    </div><!-- #container -->

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

  • avatar
    Last edited:
    02/13/11
    10:16pm
    Denzel Chia says:

    Hi,

    The below codes should be within your loop.php and not after get_template_part('loop','index')


    the_content();

    if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.

    echo "<section class='featuredimage'>";

    the_post_thumbnail("full");

    echo "</section>";

    }


    There should be the wordpress loop within your loop.php, anything outside it will not be included within the loop.

    In other words, your code is wrong.
    And you should post the code of your loop.php here and increase the price money to at least $20.

    $5 dollar will only get you suggestions and not written code solution.

    Thanks.

    • 02/13/11 10:20pm

      Denzel Chia says:


      I am looking to retrieve the content from the page that has been defined as "the posts page" in the wordpress back end.


      And to make things clearer, there is no posts page in wordpress. A post is a post and a page is a page, so what do you want exactly? Perhaps its a custom post type that you want?

      I think it is better for you to re-phrase your question.

      Thanks.

    • 02/13/11 10:45pm

      Denzel Chia says:

      @Micheal Fields - Thanks for the clarification. I did not know Matt was referring to Settings for assigning Front Page Displays.

  • avatar
    Last edited:
    02/14/11
    12:01am
    Michael Fields says:

    Please try the following code after your WordPress loop:

    /* If a page has been assigned to display posts. query for that pages data and create a custom loop. */
    $posts_page_id = get_option( 'page_for_posts' );
    if ( ! empty( $posts_page_id ) ) {
    $posts_page = get_post( $posts_page_id );
    if ( isset( $posts_page->ID ) ) {
    $_post = $post;
    $post = $posts_page;
    setup_postdata( $post );
    the_title( '<h2>', '</h2>' );
    the_content();
    $post = $_post;
    }
    }


    Best wishes,
    -Mike

    • 02/13/11 10:26pm

      Michael Fields says:

      @Denzel Chia - Please navigate to Settings -> Reading -> Front page displays to see what Matt is referring to. WordPress has had an optional posts page for quite some time now.

This question has expired.





Current status of this question: Completed



Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

If the asker does not get an answer then they have 10 days to request a refund.