Psuedo-static Homepages in Wordpress

Note: This post is over a year and a half old. You may want to check later in this blog to see if there is new information.

I use Wordpress for a lot of my smaller client sites. It actually makes a decent CMS with a little hacking. It defaults to a blog style home page, but it’s simple to create a static page, old school style. However, I’ve had several clients lately that love the idea of a blog style front page that allows them to keep content fresh, but can’t get away from the idea of having the “About” information be the first page. So I came up with several workarounds, one of which I’ll detail in this post. It uses a “Banner” category to create a sticky post at the top of the page, and then a secondary query that excludes the Banner category to fill in either below the banner or next to it, depending on your design.

Create a category

Manage CategoriesBasically, all you need to do is create a category called Banner (or whatever you like). Take note of the ID of the category in the Category Management page of the Wordpress admin panel. Now you’ll create a post (or more than one) and assign it to this category.

Set up the Home Page

Next you’ll create a file in your theme directory called “home.php”. If Wordpress detects a file with this name, it becomes the default home page. This allows us to customize the start page outside of whatever theme we’re using. So set up your XHTML to contain the banner post and add a query that only grabs the Banner category.

<?php query_posts('cat=4&showposts=2');?>

You can show multiple posts with the “showposts” parameter. I allow for 2 posts in the Banner category, if they don’t use the second post, it won’t display.

Show the post

Next you set up your loop to display the actual post(s). I set mine up to include a headline, not linked, and the post, with no date or meta information, and definitely no comment options.

<?php if (have_posts()) : ?>

<?php while (have_posts()) : the_post(); ?>

<div class="post" id="post-<?php the_ID(); ?>">

<h2 class="articleHeadline"><?php the_title(); ?></h2>
<p class="article">
<?php the_content('Read the rest of this entry »'); ?>
</p>
</div>
<?php endwhile; ?>
<?php endif; ?>

Add the news

You can then follow that with a query that either includes just a news category, or excludes just the banner category. You can copy the rest of the code out of the standard loop and edit the parameters to fit your needs. For more information on the query_posts command, see the Wordpress Codex page.

Another Solution

One of my other methods is to actually create a page template for home.php that includes home as a static page and then adds a sidebar with an “asides” category. You can get the gist of how to do this by studying the K2 code.

» » » » » »
  1. weldon 03.09.07 / 6pm

    This is great. I’m going to use this solution on a site I’m building right now. I think what I’ll do is create a category called HomeBanner and then pull the most recent post from that to fill the top of the page, then pull a certain number of posts from the News category to fill out the rest of the page.

    If I’m right, the client can then update the banner at the top of the page just by creating a new post in the HomeBanner category. That way, they’ll have a history of what they’ve done with that banner text in the previous posts.

    I just need to read up on excluding categories so that these posts don’t show up in the general feed.

  2. Brett Terpstra 03.09.07 / 7pm

    You can use in_category to exclude posts. What you describe is what I’ve done for a couple of clients, giving them a kind of sticky option and permanent header. BTW, if you’re using the adhesive plugin, in_category gets funky. If you have problems, disable adhesive.

  3. Circle Six Blog » Blog Archive » Online Magazine Tutorial: Part 1 03.21.07 / 3am

    […] Wordpress looks for to create the front page of the blog, allowing for the creation of a static or pseudo static homepage. We created 2 categories, “banner” and “secondary”, underneath a main category called “articles”. […]

  4. John 06.03.07 / 3am

    Very nice site!

  5. werutzb 10.07.08 / 9pm

    Hi!

    I want to improve my SQL capabilities.
    I red that many SQL resources and want to
    get more about SQL for my position as oracle database manager.

    What can you recommend?

    Thanks, Werutz

  6. ????? 10.15.08 / 11pm

    ????? ?????????? ?????, ??? ??? ???????????, ??????…
    ??????? ????? ????????? ? ???????????, ? ??? ???????? ?? ?????.

Have your say

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>




Safari hates me