Get More out of WordPress Link Categories

Doug Support

UPDATE: August 1, 2013

The WordPress Links Manager has since been depreciated. Any virgin installments newer than 3.0 won’t have it, but you can add the feature back with the Link Manager plugin.

ORIGINAL POST:

The WordPress platform comes with an intriguing – yet often neglected – link managing feature in the Dashboard menu called Links. What’s intriguing is the potential power of this feature, particularly with respect to Link Categories. I emphasize potential power because it’s stock usage is currently limited to a sidebar widget. As Lanexa.net has recently been tasked with redesigning a site that maintains a substantial amount of external links, this article will demonstrate an easy way to increase the functionality of the link managing feature – by creating a landing page for your Link Categories (a.k.a. Bookmarks), which can be accessed from your main menu.

Step-by-Step

1. Create Desired Categories. In the WordPress Dashboard, go to Links > Link Categories to create the Name & Slug of the the categories you will be using. It’s not important to complete this step right away, but you’ll want to get a few things in there so you’ll have something to display further on.

2. Decide which Page Template to Use. This example will use the theme’s default template called page.php. If you’re working on a live site and don’t want to risk screwing something up, you can copy this template file and rename it, i.e. page-bkmrks.php.

3. Create the Landing Page From the Dashboard, add a new page and title it what you will, i.e. Bookmarks Lading Page. Select the template you will be using and save the page. Make note of the permalink url, underneath the title, before leaving the page. I recommend using pretty permalinks, for added convenience (and a million other reasons).

4. Edit the Template. Good code-editing software – such as Coda – will allow you to log on to your server, locate the active theme folder, duplicate & rename the appropriate file (if necessary), and open it up for editing. All you have to do now is insert this simple hook into the content div:


<?php
if (is_page('bookmarks-landing-page')) {
wp_list_bookmarks();
}
?>

Note: Using pretty permalinks allows me to select the page by title.

5. Visit Your New Bookmarks Landing Page. You will notice that all your bookmarks are displayed on the page, organized under their category titles. If this is all you are looking to do, you are free to add this page to your main menu like you would any other. For more advanced options, read on (or search “wp_list_bookmarks“).

6. Select which Categories to Display. You can modify the above code in order to customize which link categories will be displayed on which page:


<?php
if (is_page('bookmarks-landing-page')) {
wp_list_bookmarks('categorize=1&category=2,5');
}
?>

Note: categorize=1 will list the links beneath their corresponding category title, while categorize=0 – also categorize= (no value) – will list links under the general heading Bookmarks.
Note: category=2,5 calls the desired link categories by their ID numbers. A category’s ID number is revealed in the URL while editing it from the Dashboard.

Or, perhaps it makes more sense to exclude a category from the list:


<?php
if (is_page('bookmarks-landing-page')) {
wp_list_bookmarks('categorize=1&exclude_category=3,4,6');
}
?>

7. Display Different Categories on Different Pages. Create as many pages as you want (using the same template) to display as many different category combinations as you want. All you need to do is stack these conditional statements, one after the other:

<?php
if (is_page('bookmarks-landing-page')) {
wp_list_bookmarks();
}
?>

<?php
if (is_page('bookmarks-landing-page-2')) {
wp_list_bookmarks('categorize=0&exclude_category=3');
}
?>

<?php
if (is_page('bookmarks-landing-page-3')) {
wp_list_bookmarks('categorize=1&category=3,4,8');
}
?>

Note: A complete list of parameters is available in the WordPress Codex.
We hope to develop this functionality into a Plugin in the coming months. Until then, i hope you find this solution to be an easy-to-manage alternative.