5

I made a home.php file and called it Blog.

It set it to be the Posts page, but I would like to add a title that will be displayed in that page (the title of page or content).

e.g:

Posts page:

    Page title
    (Maybe page content)

    == Posts ==

    Post Title
    Post Content

Post Title and so on
2
  • home.php file and called it Blog not sure what you mean here. home.php is template name reserved for home page, if you are trying to use it for named page template it will likely conflict.
    – Rarst
    Commented Jan 25, 2011 at 9:37
  • 1
    Please clarify as Rarst said, are you using a native template file, ie. a file you just drop in a theme folder, or a named page template(ie. a file you attach to the page), note: it can't be both(that won't work correctly - as Rarst also pointed out).
    – t31os
    Commented Jan 25, 2011 at 10:59

2 Answers 2

12

I'm assuming the following:

  1. You're using a Static Front Page
  2. You have a separate static page assigned to display the blog posts index
  3. You have created the home.php template file in your Theme
  4. The static page assigned to display the blog posts index is titled Blog
  5. You have added some post content to this static page

Because of the special, reserved nature of home.php, and also for page_for_posts, you cannot use the normal methods to access the $post object for the Blog static page. You can, however, retrieve the post title and post content for this page. The key is to reference the post ID via get_option( 'page_for_posts' ).

Page Title

Use get_the_title():

echo apply_filters( 'the_title', get_the_title( get_option( 'page_for_posts' ) ) );

Page Content

Use get_post_field():

echo apply_filters( 'the_content', get_post_field( 'post_content', get_option( 'page_for_posts' ) ) );

In both cases, wrap the output in an apply_filters() call, so that the post title and post content are rendered the same as they would be normally. Otherwise, the data returned via get_the_title() and get_post_field() would lack the usual formatting that WordPress applies via the_title() and the_content(), respectively.

9

as what I understand, you need single_post_title()

1
  • This is the correct answer.
    – kjdion84
    Commented Jan 25, 2017 at 6:10

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.