Page Lists Plus v0.1.7

There have been various updates to Page Lists Plus since I last blogged about it here, so it’s time for a quick catch-up. Here are some of the more recently added features:

Remove Title Attributes

By default, WordPress adds a title attribute to every link in a page list, duplicating the title of the page linked to as both the link text and the title attribute value.

This is a misuse of the title attribute. Title attributes should be used to provide additional information where it’s needed, not to duplicate all information.

You can now use Page Lists Plus to remove title attributes from your page lists, reducing code bloat and improving accessibility.

Custom Title Attributes

Sometimes, though, a title attribute that provides further information about a link can help. In that case, you don’t want to remove the title attribute, but to change its value. Page Lists Plus now lets you do that too, giving you the chance to improve your website’s usability and accessibility.

Nofollow Links

Page Lists Plus is often used to add external links to Page lists. By creating a dummy page, and then using PLP’s option to redirect links to it elsewhere, you can insert any link you want anywhere you want in your Page lists.

If you have a policy of adding rel=”nofollow” to external links to tell search engine bots not to follow them, then you’ll want to be able to nofollow external links in Page lists too. You may also want to nofollow certain links to concentrate PageRank on particular parts of your site for SEO reasons. Page Lists Plus now lets you do this.

Open Links in New Windows

You may also want to add target=”_blank” to links to external sites in Page Lists, so that they open in a new browser window. Page Lists Plus now lets you do this too (but do be aware that target=”_blank” won’t validate if you’re using a strict rather than a transitional doctype).

Most of these features have been added in response to requests by users. If there’s something that you’d like Page Lists Plus to do that it doesn’t already, then please make a feature request of your own.

WordPress provides a template tag that outputs all of the categories to which a post belongs: the_category(). You might use this to create a complete, comma separated list of a post’s categories using something like this: <p class="postCategories">Categories: <?php the_category(', '); ?></p>.

Sometimes, though, you don’t want a complete category list, because some of your categories are for administrative use only. Unfortunately, there’s no easy way to generate an incomplete category list. You can’t just pass a variable to this function excluding a category; the_category('exclude=1') doesn’t work.

So if we want an incomplete category list then we need to create our own custom function. Adding the following code (adapted from code suggested by MichaelH on the WordPress forums) to your functions.php theme file will create a function that generates a comma separated list of a post’s categories excluding “FirstCat” and “SecondCat”:

function incomplete_cat_list($separator) {
  $first_time = 1;
  foreach((get_the_category()) as $category) {
    if ($category->cat_name != ‘FirstCat’ && $category->cat_name != ‘SecondCat’) {
      if ($first_time == 1) {
        echo ‘<a href=”‘ . get_category_link( $category->term_id ) . ‘” title=”‘ . sprintf( __( “View all posts in %s” ), $category->name ) . ‘” ‘ . ‘>’  . $category->name.’</a>’;
        $first_time = 0;
      } else {
        echo $separator . ‘<a href=”‘ . get_category_link( $category->term_id ) . ‘” title=”‘ . sprintf( __( “View all posts in %s” ), $category->name ) . ‘” ‘ . ‘>’ . $category->name.’</a>’;
      }
    }
  }
}

To use this function, just add something like this to your index.php or single.php theme files: <p class="postCategories">Categories: <?php incomplete_cat_list(', '); ?></p>.

Replace “FirstCat” (”SecondCat”, etc.) with the names of the categories that you want to exclude. If you want something other than a comma between categories, then change the value of $separator passed when you call the function.