Adding general page content to page templates

I’m having trouble doing the same for a page that is called from WP Settings as the “Posts Page”. Let’s say at the top of the “Blog” page (a WordPress page), I want some intro text to the blog that says, “Welcome to the blog. Please check out new posts below.” Instead of hardcoding that into the template, how would that be achieved?

First, understand that, per the WordPress Template Hierarchy, the template files used in this context are, in order of preference: home.php, and index.php. Nothing you do to a custom page template will have any impact on what WordPress uses to render the Blog Posts Index.

Your best solution here would be to hard-code this text into home.php, outside the Loop. You could put this text inside a template-part file, and call it via get_template_part( $foobar ) if you really wanted to, but doing so honestly serves no purpose here.

By the way: what is your aversion to hard-coding template-specific text into a template file?

p.s. here is a more current version of the Template Hierarchy. (I’ll be adding it to the Codex shortly.)

EDIT

I am working on a theme that will be distributed/available to dozens, if not hundreds of different clients. I’d like clients to be able to control if there is any intro text within the blog area.

I really don’t think you can output the $post->post_content for the static Page used as page_for_posts. Maybe you could use a custom query, e.g. using get_page():

<?php
$page_for_posts = get_page( get_option( 'page_for_posts' ) );
$page_for_posts_content = $page_for_posts->post_content;
echo apply_filters( 'the_content', $page_for_posts_content );
?>

Alternately, I would suggest one of two approaches:

  1. Create a Theme Option to define this text/content
  2. Make that part of the template file a dynamic sidebar, and let users add a Widget – e.g. a Text Widget – in which they can define this text/content

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)