Another WordPress Development Blog

Static content on a wordpress home page


If you are building a custom home page for your wordpress blog you may need to display a static piece of content. For example you need an ‘About us’ text that will sit around the latest ten excerpts.

Of course, you can do this by directly editing the index.php but what happens if this content need to be updated from time to time and the persona that will do this is not a technical one.

The solution is to create a special page and use the content on home page. Here is how you can do this.

First you need to create a page named ‘Front Page’ . Post here the content you want on the front page.

Second, copy /paste the code below in your index.php. Make sure you not inserted in the posts loop.


$arg=array( 'post_type'=>'page',
'name' => 'front-page',
);

query_posts($arg);
while (have_posts()) : the_post();
the_content();
endwhile;

That’s it. Just make sure you exclude the ‘Front Page’ from any page lists you have. You don’t need a duplicate content issue.

PS: you can use any name for this page. Just make sure you use the post slug and not the title on this line: ‘name’ => ‘front-page’,

Random Posts

Leave a Reply