Fri
Nov 16
11:30am
Taking Wordpress beyond the standard install
I’ve almost finished a relatively simple Wordpress 2.3.1-run site for a project at work and thought I’d share a few of the “extras” I included to take it beyond the standard install.
I’ve used Wordpress for a few sites now (including martinjy.com) but haven’t really explored it beyond a few plugins and some style tweaks. This project called for more effort than that. In addition to a straightforward blog section with latest posts and date-based and category archives, the site requirements that are relevant to list here were:
- Static homepage (1-col layout) including latest blog posts
- Around 15 other static pages (2-col layout), including sub-pages
- Good search
- Unique look and feel
Blog
Setting this up was relatively easy. After all, it’s what Wordpress does out of the box. The only additions to the standard functionality are the Fuzzy Recent Posts plugin, a bit of Sidebar tweaking to organise things in the right order, and an Include for some static contact information. I used an Include because that info also appears on the homepage and I didn’t want to have to update it in multiple places when it changes. As I’m reviewing it now I realise I probably should have written a Page for it and included that instead of a theme page - this will make it easier for the site owner to update it herself. (Note to self: do that before launch and remember to exclude the page from the menus).
I couldn’t have used the Widget Sidebar functionality to organise the sidebar as it wouldn’t have given me the flexibility I needed. I can see why the widget sidebar will become very popular with non-coders, standard blogs and/or lazy types though.
On the blog entries themselves I did a bit of styling and set up images so that they will always float on the right of the post. Comments are off by default for the entire site but I left the code to display them there anyway just in case the site owner changes her mind in the future.
Pages
So. Blog done. Here’s where things started to perk up a bit.
Writing pages (i.e. non-time-dependant content) is easy (read about them here). But the sidebar on my Pages needed to be different to the Blog sidebar - I didn’t want the Recent Posts or Archives to show up. A bit of Googling and Wordpress-codex researching told me that all I needed to do was create a Page template, as Wordpress looks for a Page template when it’s trying to display a Page. If it finds one it uses it. If it doesn’t find one it uses the standard template.
So I made a copy of the standard template, called it page.php and FTP’d it into the theme folder alongside the index.php file. I did the same thing with the sidebar file, naming it page-sidebar.php and changing the name of the Blog sidebar to blog-sidebar.php. With those all in place I made sure that index.php called blog-sidebar.php (
Warning: include(page-sidebar.php) [function.include]: failed to open stream: No such file or directory in /home/ularykhz/public_html/blog/wp-content/plugins/exec-php/includes/runtime.php(42) : eval()’d code on line 23
Warning: include(page-sidebar.php) [function.include]: failed to open stream: No such file or directory in /home/ularykhz/public_html/blog/wp-content/plugins/exec-php/includes/runtime.php(42) : eval()’d code on line 23
Warning: include() [function.include]: Failed opening ‘page-sidebar.php’ for inclusion (include_path=’.:/usr/lib/php:/usr/local/lib/php’) in /home/ularykhz/public_html/blog/wp-content/plugins/exec-php/includes/runtime.php(42) : eval()’d code on line 23
) and page.php called page-sidebar.php (
Warning: include(page-sidebar.php) [function.include]: failed to open stream: No such file or directory in /home/ularykhz/public_html/blog/wp-content/plugins/exec-php/includes/runtime.php(42) : eval()’d code on line 23
Warning: include(page-sidebar.php) [function.include]: failed to open stream: No such file or directory in /home/ularykhz/public_html/blog/wp-content/plugins/exec-php/includes/runtime.php(42) : eval()’d code on line 23
Warning: include() [function.include]: Failed opening ‘page-sidebar.php’ for inclusion (include_path=’.:/usr/lib/php:/usr/local/lib/php’) in /home/ularykhz/public_html/blog/wp-content/plugins/exec-php/includes/runtime.php(42) : eval()’d code on line 23
). I’m sure I could have done that with some sort of if-statement in php but couldn’t be bothered trying.
Then I amended page-sidebar.php to remove the Archive and Recent Posts code. Done.
Sub-Pages
Had to research these a bit before I dived into them, but they’re pretty easy to handle. 1. Create a Page that will be the parent of the set of Sub-Pages. 2. Create another Page that will be the Sub-Page, then select the “parent-page” from the pull-down on the right and save. Repeat for all your Sub-Pages.

Making it easy for users to navigate to the Sub-Pages is reasonably straightforward. First I modified my wp_list_pages calls in the top menus in page.php and index.php to a depth of 1 to stop all the sub-pages showing up there. See the wp_list_pages template tag in the Codex for more info. Then in my page-sidebar.php I inserted a piece of code from that same Codex page that displays the Sub-Pages of the Page we’re on whether we’re on the parent page or one of the Sub-Pages. Presumably if you had another section of the site with different Sub-Pages that same code would work to display those instead, but I can’t confirm that as I haven’t tried it.
Homepage
This is the one part of the site that had me stumped. For the life of me I couldn’t work out how to use Wordpress’ new “Front page displays a static page” functionality (Options > Reading). Eventually I found this write-up from another Wordpress user, Richard Sipe, that explains what was happening … the functionality is there but the Codex documentation regarding how to use it is old and out-of-date.
It’s pointless for me to repeat what Richard has already documented except to confirm that his method works (and to thank him for sharing it!).
I modified two more things regarding the homepage:
- It needed a one-column layout. I achieved this by splitting my Page template into two … or in other words adding a conditional tag in page.php that says “if this is the homepage, use the homepage layout. Otherwise use the standard page layout.”. Pretty straightforward.
- I wanted the feature part of the page to be a Page that could be updated by the site owner, so I Googled again and found the iinclude plugin. I’ll also use this to include the Contact info that I mentioned above.
Before I forget - divs
The special layout for the homepage (and one of my other pages) required me to use divs, but I found that whenever I added a div the Wordpress TinyMCE editor was removing it. That annoyed the hell out of me until Google saved me once again. Read this page to find out how to hack the editor to stop that from happening.
Search
Unfortunately Wordpress’ Search only searches posts, not pages. That was no good to me. Also, by default it returns the full post in search results. Also no good to me. At least it *has* a search, I suppose.
So it was back to Google, where I found the Search Everything plugin. I downloaded and installed that, then created a custom Search Results template. (Again, WP knows to display that template for search results if it exists). Part of that template included the_excerpt to chop off posts and pages after a few lines.
404 page
This is another one-hour task that can be of great benefit to your readers. It’s just another custom template that, again, WP knows to use if it exists. Worthwhile.
Phew. I think that’s just about it for now. About the only other thing I can think of is I tried to use the Sliding Doors of CSS II method for my top navigation, but it’s not implemented perfectly at the moment so I don’t think there’s much point in sharing what I’ve done. Maybe in another post when I’ve got it right.