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:
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.)
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
$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:
- Create a Theme Option to define this text/content
- 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