A Path Less Taken

Breaking with convention in a very conventional fashion. Powered by WordPress

"What would you attempt to do if you knew you could not fail?"
Dr. Robert Schuller

Saturday, July 11, 2009

Category: Web Design Author: JJ 0 Comments

As we push our way through the process of building a WordPress theme, it’s easy to get bogged down in little details and lose site of the big picture. If we are patient and search, we can uncover a lot of useful content on the WordPress site. Just take a look at the information here. About 3/4 of the way down the page you will find the Theme Template Files List. This list is useful as a high level road map for building your first theme.

Some of the pages are familiar to you now. Others we have not worked on yet. Take a few minutes to read about each page and its function. Also take some time to scan through the rest of that page. It has some good information for the aspiring theme developer.

One template that our theme still needs is the single.php template. If it’s available in our theme then WordPress uses it when displaying a single post. If it’s not there, WordPress uses the index.php template. This would be fine if it wasn’t for the navigation links. Index.php is designed to page multiple posts at a time. When it is used to display a single post the navigation links, which are built for multiple posts, are not displayed.

To remedy this I created a single.php file for our Welcome theme. I then copied the entire index.php contents into that file. I took out the multiple post link generation code near the bottom. Then I added a new section right below the footer section of the post. Below is the code I added.

1
2
3
4
5
6
7
8
 
			<!-- Single Post Navigation -->
			<div id="postNavLinks">
<?php
				previous_post_link ('&lt;&lt; %link &nbsp;') ;
				next_post_link ('&nbsp; %link &gt;&gt;') ;
?>
			</div><!-- close postNavLinks -->

The previous_post_link() and next_post_link () functions provide single post navigation links. The string allows for formatted display of the output with %link reperesenting the link position in the output to accompany whatever other text we provide. Once the changes were saved I previewed the blog, selected a single post to view and confirmed the navigation links were correct.

This worked fine, but I really have a problem with the approach. If I should change either the single.php or index.php files then most of the time I will have to change the other file to match. This puts a significant burden on the theme creator for updating either template. I’m not certain at this point what can be done to resolve this. For now we will use our single.php and hope that it and index.php don’t change for a while.

No comments found. Please enter a comment if you have a question or contribution.

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">