Today is definitely a ‘futz with WordPress’ day. Upgraded everything to 2.5.1, and now I’m working on a new site – something a bit more corporate, with a static main page and the blog on a subpage. I therefore wanted a navigation bar that had the blog as one of the links. The standard way to do a navigation bar is through the powerful wp_list_pages() WordPress template tag – but this lists just the static pages, not the main posts page.
For a while I was considering hard-coding something or trying to create a filter – until I stumbled across the solution on my own. (Looks like it’s one of those ‘supported but not documented’ things.) First, go create a static page and call it what you want your blog to appear as in the navigation bar – ‘Blog’, ‘Diary’, whatever. Type whatever you want in the body of the page – it’s just a fake placeholder, and isn’t going to show. Next, go to Settings > Reading in the Admin UI. In the ‘Front page displays’ section, select the ‘a static page’ radio button, and then choose the static page you want to show as the ‘Front page’ from the dropdown. Select the static page you just created (‘Blog’, or what-have-you) as the ‘Posts page’. Save your settings.
That’s it – wp_list_pages will now return a link to your main blog along with all the other static pages. Note, however, that you can’t add your blog as a link in wp_list_pages if you also want it to be the front page of your site – if you set the ‘Front page’ and ‘Posts page’ to the same page it causes a warning, and the site shows the content of the fake static page you created rather than your blog posts.
Hopefully WordPress will make adding your blog to wp_list_pages simpler in the future (or create a wp_nav_bar tag that includes it), and allow the blog to both be the main page and in the nav bar simultaneously.
{ 1 comment… read it below or add one }
“…Note, however, that you can’t add your blog as a link in wp_list_pages if you also want it to be the front page of your site…”
If you select the static page you just created as the ‘Posts page’ and as the ‘Front page’ you don’t select anything, it will add your blog as a link and it will also be your front page.
At least it works for me.