Linkify Categories

Author:Scott Reilly
Version:1.1
Last update:06 Jan 2010
Compatibility:WP 2.8+, 2.9+
Comments:go here
Download:[ zip ]
Description:

Turn a string, list, or array of category IDs and/or slugs into a list of links to those categories.

Extended Description

Turn a string, list, or array of category IDs and/or slugs into a list of links to those categories.

These are all valid calls:

<?php linkify_categories(43); ?>
<?php linkify_categories("43"); ?>
<?php linkify_categories("books"); ?>
<?php linkify_categories("43 92 102"); ?>
<?php linkify_categories("book movies programming-notes"); ?>
<?php linkify_categories("book 92 programming-notes"); ?>
<?php linkify_categories("43,92,102"); ?>
<?php linkify_categories("book,movies,programming-notes"); ?>
<?php linkify_categories("book,92,programming-notes"); ?>
<?php linkify_categories("43, 92, 102"); ?>
<?php linkify_categories("book, movies, programming-notes"); ?>
<?php linkify_categories("book, 92, programming-notes"); ?>
<?php linkify_categories(array(43,92,102)); ?>
<?php linkify_categories(array("43","92","102")); ?>
<?php linkify_categories(array("book","movies","programming-notes")); ?>
<?php linkify_categories(array("book",92,"programming-notes")); ?>

Examples:

<?php linkify_categories("43 92"); ?>
Displays something like:
<a href="http://yourblog.com/category/books">Books</a>, <a href="http://yourblog.com/category/movies">Movies</a>

<?php linkify_categories("43, 92", "<li>", "</li>", "</li><li>"); ?></ul>
Displays something like:

<ul><li><a href="http://yourblog.com/category/books">Books</a></li>
    <li><a href="http://yourblog.com/category/movies">Movies</a></li></ul>

<?php linkify_categories(""); // Assume you passed an empty string as the first value ?>
Displays nothing.

<?php linkify_categories("", "", "", "", "", "No related categories."); // Assume you passed an empty string as the first value ?>
Displays:
No related categories.

Find out more at the plugin’s WordPress Plugin Repository page.


Installation

  1. Unzip linkify-categories.zip inside the /wp-content/plugins/ directory for your site (or install via the built-in WordPress plugin installer)
  2. Activate the plugin through the ‘Plugins’ admin menu in WordPress
  3. Use the linkify_categories() template tag in one of your templates (be sure to pass it at least the first argument indicating what category IDs and/or slugs to linkify — the argument can be an array, a space-separate list, or a comma-separated list). Other optional arguments are available to customize the output.

Template Tag

This plugin provides 1 template tag(s).

Function

linkify_categories($categories, $before = '', $after = '', $between = ', ', $before_last = '', $none = '')

Displays links to each of any number of categories specified via category IDs and/or slugs

Arguments

  • $categories : A single category ID/slug, or multiple category IDs/slugs defined via an array, or multiple category IDs/slugs defined via a comma-separated and/or space-separated string
  • $before : (optional) To appear before the entire category listing (if categories exist or if ‘none’ setting is specified)
  • $after : (optional) To appear after the entire category listing (if categories exist or if ‘none’ setting is specified)
  • $between : (optional) To appear between all categories
  • $before_last : (optional) To appear between the second-to-last and last element, if not specified, ‘between’ value is used
  • $none : (optional) To appear when no categories have been found. If blank, then the entire function doesn’t display anything

Release Log


Copyright & Disclaimer

Copyright © 2009-2010 by Scott Reilly (aka coffee2code)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.