How to Edit your Single Post Navigation on WordPress

The WordPress Codex presents that the default code and presentation of the post navigation links appears as:

Perhaps I’m a little too OCD twitchy about this, but I take issue with the navigation structuring. When I’m looking at the front page of my blog, displaying the ten most recent posts, and scroll to the bottom, it presents “Next Page ».” To my mind, though, I would not be navigating to the “next page,” but rather to the “previous page” because I would be looking at older entries. Older is always Previous to me, but WordPress is backwards in this regard.

Conversely, when accessing a single post in my primary WordPress theme (and perhaps others), it was backwards from what I now expected based on the front page of my blog. To access older articles, I would click the link on the left (denoted by the name of the entry, rather than “newer” or “older”), and newer articles were accessed by using the link on the right (which, to my mind, should be leading me into an archive). This seemed counter-intuitive considering that the full-page-post (where I have ten entries on a page, rather than just the single one) navigation had older entries on the right and newer on the left.

In essence, the navigation seemed contradictory and inconsistent. To change this, I needed to edit browse.php (though in most themes, this is located in index.php) and reverse the following conditions:

|

The aquo statement is for two left or right karat marks, and the L or R that preceeds the aquo tells them which direction to point. Therefore, when I reversed these, it became:

|

Note the spacing, which is purely for aesthetic reasons. I added the pipe (the | symbol) myself for the same reasons.

If you want your post navigation to conform to whatever OCD tendencies you might have, this code should be located in either index.php or browse.php.

What’s sort of amusing is that my stories blog, despite having older posts on the left and newer on the right (the same configuration that set off this OCD codefest to begin with) doesn’t bother me at all. Maybe that’s because it doesn’t have a sidebar and everything is centered (and the theme is built to only display one post at a time), so I wasn’t expecting older posts to be on the right or the left. And I get the initial logic: much like an English book, you turn the page from right to left, so newer content (that you haven’t read yet) is to the right… but it has to be consistent. All of your navigation links must agree, and by default on my primary theme, they did not.

Does anyone else think about visual triggers and the expectations to which they lead?

Using a Second Sidebar for Different WordPress Pages

This post was originally written when I was using a different theme. That doesn’t affect the content, just wanted to let you know that my current theme (designed by Ryan Burrell) doesn’t use this particular method. Rather, it employs various templates to display bars as necessary. For more information, check out my guide How to use page templates in WordPress.

I wrote sometime ago about the visual design of a website, particularly a WordPress blog, and lamented the long sidebar that plagues so many sites. Like anyone else, I want to show everything I have to offer to my readers, but I know that my readers don’t necessarily want the same. End-users want the information they want and nothing else that might distract them from that information. Readers want data to be concisely presented and easy-to-read. A sidebar as long as my arm detracts from these goals.

Therefore, when I added some things to my WordPress sidebar (like a blogroll) that made it particularly long, I knew something had to be done. It’s all fine and well on the main page where ten blog entries make for a rather long site (and therefore the sidebar doesn’t look out of place). But when looking at a single post, the sidebar added a dozen inches below the comment box until you reached the footer. No good.

The WordPress Codex has some tips on creating a second sidebar and using this for other pages (such as when viewing just a single post), but beyond giving me the PHP tag for the sidebar, it didn’t do me a lot of good. The theme I use did not have the sidebar statement in the default location (which is normally sidebar.php in your theme’s files), and when I did find the code I needed to change, the tag listed in the WordPress Codex didn’t work.

My sidebar actually extends up from the footer, so it was the footer.php I needed to edit. Removing the standard sidebar tag, I entered the following:

When I first made this change, I discovered that, while it worked great for posts, my pages still had the longer sidebar. Since my Contact page is pretty short, this ran into the same problem as before: the page content had ended, but the sidebar just kept going. Therefore, the code needed to be modified slightly to accommodate pages as well as single posts.

Using an elseif statement, we are able to use sidebar2.php on both pages and single posts. If you have additional templates on which you wish to use a different sidebar (say you wanted a different sidebar on the category, archive, and portfolio pages as well), you might considering using a switch, but with my limited knowledge of PHP, using if/elseif/else statements worked just fine for me.