Displaying page numbers in Wordpress
April 22, 2008
The WP Page Number PluginĀ is a great plugin for displaying page numbers for your Wordpress pages instead of the next or previous post format. This plugin replaces wordpress previous_post_link and next_posts_link and shows page numbers instead: Wp Page Numbers.
Creating a Unique Homepage using Conditional Tags in WordPress
November 26, 2007
Conditional tags in WordPress are awesome! Conditional tags (also called if statements) allow you to create content that only displays on certain pages. For example, let’s say we wanted to display a navigation bar on all of our pages, except the homepage ( a true example of something I needed to do for a client). So, we can use conditional tags to do this, but there are a few nuances. Let’s explore…
Using the code from the link above, we might arrive at something like this to add to our header.php file:
<?php if (is_home()) {
}
else { include (TEMPLATEPATH . ‘/navbar.php’);
}
?>
In this example, the first if statement is saying if this is the homepage do nothing, and including the navbar.php file for all other pages. This works great if we haven’t customized our blog, but we run into a problem if we’ve switch our homepage from displaying our dynamic blog posts to displaying a static page (done in the WordPress admin area under ‘reading options’). If that’s the case, then the is_home statement is still referring to our blog page, even though it’s not displaying as the homepage. So what do we do? Try adding this to your header file:
<?php if (is_page(’home’)) {
} else { include (TEMPLATEPATH . ‘/navbar.php’);
}
?>
The is_page targets whatever page we’ve switch to be our homepage. Just replace ‘home’ with whatever your static homepage name is. Now for the navbar file, we would create a separate file, called navbar.php and upload it to our theme folder. The code in that file might look something like this:
<?php
/*
Template Name: navbar
*/
?>
<div id=”navbar”>
<ul>
<li><a href=”<?php echo get_settings(’home’); ?>”>Home</a></li>
<li><a href=”/about”>About</a></li>
<li><a href=”/blog”>Blog</a></li>
<li><a href=”/contact”>Contact</a></li>
</ul>
</div>
Of course, you’d replace the links to represent the navigation you want to display, and the div id to reflect the id you’re using, or you can edit your style sheet to define the div properties. Now, when you load your website, the navigation bar will not display on your homepage, but it will display on all other pages.
You could use this same technique to change any number of things on your site to create a unique homepage, or use multiple if statements to create unique content on pages other than the homepage. For example, you might set it up so your header has a different picture for each page. Or you might create a different footer depending on the page. The possibilities are limitless using conditional tags in WordPress.
If you need help, feel free to contact me.
GoDaddy htaccess
November 23, 2007
As I discussed in my previous article, I implemented a link directory using the WP Link Directory. Everything looked good until I tried to enable pretty permalinks. For those you don’t speak geek, pretty permalinks changes ugly urls like /?cat=9 to something like /open-source. You can see how one is easily identifiable and the other is incomprehensible. Well, most people like the one that can be understood. But I couldn’t get pretty permalinks to work in my directory.
The problem here arises because usually the htaccess fie is located in your root folder, but the WP Link Directory has its own htaccess folder within the ‘directory’ folder. The code I had, which was included with the WP Link Directory plugin was:
RewriteEngine on
RewriteRule ^categories/(.*)/(.*)$ index.php?cat=$1&page=$2 [QSA,L]
RewriteRule ^subcategories/(.*)/(.*)/(.*)$ index.php?cat=$1&scat=$2&page=$3 [QSA,L]
The ^ says to look within the folder that the htaccess is in. In this case, the ‘directory’ folder. This code will probably work for any other host, but not GoDaddy. As you’ll find if you Google ‘GoDaddy htaccess,’ many people have the same problem when trying to create pretty permalinks and GoDaddy is no help. I even called them, only to receive the same response I read on every forum where I looked for answers–”We don’t provide customer support for htaccess.” Well…the standard htaccess code wasn’t working, and I didn’t have a clue why. So I kept Googling for information, and kept trying every possible solution I came across. Everywhere I looked, everyone had the same issue, and most people suggested switching hosts. Well, I’m not one to give up that easily…
After a while, I came across a post that suggested that a certain line of code was vital to creating pretty permalinks using GoDaddy htaccess. This code is:
RewriteBase /
and it must be put before your rewrite rules. This code establishes the base to be your main url. So even the htaccess file is in your ‘directory’ folder, you’re specifying the base to be your main folder. Therefore, all other urls in the htaccess file need to reflect this. So, once you include this code, you must add the full extension to the rewrite rules. I’ll do my best to explain.
The original code was:
RewriteRule ^categories/(.*)/(.*)$ index.php?cat=$1&page=$2 [QSA,L]
RewriteRule ^subcategories/(.*)/(.*)/(.*)$ index.php?cat=$1&scat=$2&page=$3 [QSA,L]
Here, the index.php?cat= code is calling a php function from the WP Links Directory plugin, and pulling some dynamic content from the database. The index.php file is within a folder called ‘directory’. Therefore, we must change the htaccess code to:
RewriteRule ^categories/(.*)/(.*)$ directory/index.php?cat=$1&page=$2 [QSA,L]
RewriteRule ^subcategories/(.*)/(.*)/(.*)$ directory/index.php?cat=$1&scat=$2&page=$3 [QSA,L]
Adding the ‘directory” extensions tells the htaccess file to look for the index.php within the directory folder. So if you the pages you are creating the pretty permalinks for are in another folder, other than the root folder, you need your rewrite rule to include the extensions to take you into that folder.
If this is confusing, I understand. I used a lot of resources to research the solution to this problem. Here are a few of them:
HTML Source on Rewriting URLs
Easy Mod Rewrite
Mod_Rewrite ReWriteRule Generator
A couple good terms to search on Google are (just click and it will take you to the search page): apache mod rewrite, , mod rewrite tutorial and of course, GoDaddy htaccess.
So, here’s the final code I implemented to get the pretty permalinks working for WP Link Directory.
# BEGIN WordPress
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^categories/(.*)/(.*)$ directory/index.php?cat=$1&page=$2 [QSA,L]
RewriteRule ^subcategories/(.*)/(.*)/(.*)$ directory/index.php?cat=$1&scat=$2&page=$3 [QSA,L]
# END WordPress
WordPress Directory Plugin
November 23, 2007
If you are using WordPress and you are interested in creating a link directory, you might consider using a WordPress Directory Plugin. Not sure why you’d want a link directory? Well…
A link directory enables you to offer a very targeted set of categorized links on your site, preferably to content related to the theme of your site. For example, the directory on my site is for web development. So all the links in the directory should be related to web development in some meaningful way.
There’s another bonus to creating a link directory: It improves your Page Rank (PR). Page Rank is something Google uses and it’s related to the number of inbound links to your site. There’s a huge algorithm for calculating PR, but for the purposes of this article, you basically want to increase the number of people linking to your site, and a link directory helps you do this by requiring that anyone who lists themselves in your directory provide a link back to your site.
So here are two WordPress Directory Plugins worth checking out:
WordPress Links Directory
I like this directory plugin because it offers a nice, clean layout. I’m also partial to the AJAX aspects of the plugin. The install was not easy, and required some modifications to some of the files in order to get it to display correctly for the theme I’m using. It seems many people have had trouble integrating this plugin with their theme, so you may not want to use it for this reason. However, the author of the plugin has added some common theme support here. This plugin supports SE-friendly permalinks, subcategories, and reciprocal-link checking, which is a major bonus. One click on the backend sends out a little spider to see if the people who say they are linking to you are really linking to you. This is dynamite for when you have a lot of links, so you don’t have to waste your time manually checking them.
WP-Directory
I decided not to go with this plugin, but it’s still worth considering. It’s set up is more like DMOZ, so if you like that style, this may be the choice for you. It also supports pretty permalinks, screenshots, subcategories, and a cool little sidebar widget. The installation looks a lot simpler too. View a demo of WP-Directory here.
If you need help installing either of these plugins, please contact me.
How to Widgetize Your WordPress Footer
November 16, 2007
Widgets are great for people using WordPress who don’t want the hassle of hard-coding their sidebar. Many themes have a widgetized sidebar or even two. But what about widgetizing your WordPress footer? I looked for a tutorial, but couldn’t find one, so I’m presenting my exploration in widgetizing my WordPress footer for future posterity.
First, open the function.php file found in your template folder. Search for the sidebar function. It should look like this:
if ( function_exists(’register_sidebar’) )
register_sidebar();
If it’s not there, add it. If you want to have multiple widget sidebars, then you need to alter the code a little bit. For example, if you wanted a widgetized sidebar and a widgetized footer, we would add this code instead:
if ( function_exists(’register_sidebars’) )
register_sidebars(2);
You could change the number 2 to reflect the number of different widgetized sidebars you want to use.
Calling the Function
To call this function when we have just one dynamic sidebar, we would use the following code in our sidebar.php file or footer.php file, depending on where you want the sidebar:
<?php if ( !function_exists(’dynamic_sidebar’) || !dynamic_sidebar() ) : ?>
However, if we have multiple sidebars, we’ll use this code for the first sidebar:
<?php if ( function_exists(’dynamic_sidebar’) && dynamic_sidebar(1) ) : else : ?>
And this code for the second sidebar, to be placed in the footer.php file if you want a widgetized footer:
<?php if ( function_exists(’dynamic_sidebar’) && dynamic_sidebar(2) ) : else : ?>
To end the dynamic sidebar, add this code:
<?php endif; ?>






Recent Comments