0

I'm very new to WordPress, but I'm currently doing work on a site built on the platform. I'm making my way through, but I've run into a bit of a problem.

I'm trying to add content from the text editor of the site's blog page, which uses the standard index.php template. However, when I use <?php the_content(); ?> like other pages use, it returns the content of the latest post. Is there a way to get the content from the page editor instead?

I've been looking all morning without really finding anything satisfactory. Any advice would be greatly appreciated!

            <section id="primary" >
                <?php the_content(); ?>
                <div class="content" role="main" data-target="index" >

                    <?php if (have_posts()) : ?>

                        <?php get_template_part('inc/loop', get_post_type() ); ?>

                    <?php else : ?>

                        <?php get_template_part('inc/content', 'none' ); ?>

                    <?php endif; ?>

                </div><!-- end content -->
            </section><!-- end primary -->
1

2 Answers 2

0

When you configure your blog (posts) page under Settings > Reading, that page becomes nothing more than a placeholder - in other words, you won't be able to grab it's title/content within index.php without a little trickery:

if ( $page_id = get_option( 'page_for_posts' ) ) {
    echo get_the_title( $page_id );

    // the_content() doesn't accept a post ID parameter
    if ( $post = get_post( $page_id ) ) {
        setup_postdata( $post ); //  "posts" page is now current post for most template tags        
        the_content();
        wp_reset_postdata(); // So everything below functions as normal
    }
}
0
0

I think you want to set a page as the home page rather than a post. You can set this using wordpress settings. You have to set a selected page that will display on the site's home.

  • Login to admin end and go to Settings -> Reading
  • Select the 2nd option (A static page) for the setting Front page displays
  • Then select the page from the dropdown list for Front page whichever you want to set as the home page.
  • Save the settings.

Now if you check your site, you should see a page rather than post.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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