Edit text on your WordPress home posts page

Posted on November 2nd, 2010 at 6:40 pm

So, you’ve gone into your Settings / Reading admin area and selected a page to be your new ‘front page’ and you’ve selected another page to be your ‘posts page’ (from now on refered to as ‘home page’).

Everythings great. Your new front page can be edited in the usual way and your blog posts are listed on your new home page. Well done!

But your client wants to add some text to the top of the new home page. You go to input some text on the edit page screen but it’s not appearing. The only thing appearing in the main content area are your posts. What IS happening to that text? Well it’s not going to appear I’m afraid. Unless you do the following:

First have a look and see if you have a ‘home.php’ file in your theme directory. If you haven’t then just copy the index.php file and rename to home.php.

Now we edit the home.php so that it can display that content. Open up your editor and add this nice piece of code a line above the if (have_posts()) line near the top.

<?php
$page_id = 35;
$page_data = get_page ( $page_id );
$title = $page_data->post_title;
$content = $page_data->post_content;
echo $title;
echo apply_filters( 'the_content', $content );
?>

Now the only thing you’ll really need to edit there is the $page_id variable, currently set to ’35’. You need to find the page ID of your new home page first. Go to your edit pages screen and hover your mouse over the new home page. In the link URL you’ll see the number you need, just after ‘post=’. Replace the 35 with that and you should be up and running.

Just edit the text as you would any ordinary page and it should appear above the normal blog posts, and only on the new home page.

This entry was posted on Tuesday, November 2nd, 2010 at 6:40 pm and is filed under Web Design, WordPress. You can follow any responses to this entry through the RSS 2.0 feed.

3 comments so far.

Please add a comment