Support » Developing with WordPress » How to use the_title(), the_content() and the_excerpt on Blog landing page

  • When I use the_title(), the_excerpt() or the_content() on my Posts (AKA Blog landing) page I do not get them. Rather, I get them for the first Post on the page.

    I have tried passing the Page ID, but it’s passing the Posts ID instead. I have also tried wp_reset_query().

    What am I missing? Thank you!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator Steven Stern (sterndata)

    (@sterndata)

    Forum Moderator & Support Team Volunteer

    You have to use those in the loop, as they refer to the current post, so when you do

    while (have_posts()) {
      the_post();
      // other stuff
    }

    the line the_post() sets the current post.

    to get the title and content of the ‘blog’ page (as set under ‘settings – reading’), you might need to add a custom query with loop into index.php (or home.php if exists), or alternatively use some code in functions.php of your heme, like in my example (code, particular the html tag structure, is for Twenty Fourteen):

    function page_content_on_posts_page() {
    if( get_option( 'page_for_posts' ) && is_home() ) {
    global $wp_query;
    if( !is_paged() && $wp_query->current_post == 0 ) { ?>
    <article id="post-<?php echo get_option( 'page_for_posts' ); ?>" class="<?php echo implode(  ', ', get_post_class( 'posts-page-content', get_option( 'page_for_posts' ) ) ); ?>">
     
    <div class="entry-content">
    <?php
    echo apply_filters( 'the_content', get_post( get_option( 'page_for_posts' ) )->post_content );
    ?>
    </div><!-- .entry-content -->
    </article><!-- #post-## -->
    <?php }
    }
    }
     
    add_action( 'the_post', 'page_content_on_posts_page' );
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to use the_title(), the_content() and the_excerpt on Blog landing page’ is closed to new replies.