Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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
share|improve this question
    
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 Jan 25 '11 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 Jan 25 '11 at 10:59
add comment

2 Answers

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.

share|improve this answer
add comment

as what I understand, you need single_post_title()

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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