Link Listing in WordPress

WordPress supports the ‘Blogroll’ model for links, which works fine for links but I wanted to be able to put together a series of pages listing links on different subjects for my CommunityNet project.

For example, I wanted to have links grouped into such topics as ‘Think Tanks’, ‘Animal Welfare Groups’, etc.  I couldn’t work out a way of doing this in a manageable fashion through the existing WordPress functionality.  I had a look around for Plugins but found nothing that seemed sensible for what I wanted, so I decided to ‘homebrew’. 

Elsewhere in this blog I mention the use of WordPress Templates and so decided to develop a solution whereby each ‘Category’ of links would be on a separate page, and the page would contain the list of links.

Setting up the links

First of all, I imported the links I had in to the links table in the WordPress database.  As there were relatively few, and they hadn’t yet been categorised, I just created an INSERT SQL scrip and ran them in with phpmyadmin.  Alternatively, I could have simply added them in under the Blogroll option in the WordPress Dashboard.

I then set up the categories I desired, and made a note of the ‘ID’ value allocated by WordPress to each category.  Finally, I allocated the links to the desired category.

Create a Template

I followed my own instructions, in the link above, and created a template page within the relevant theme for each category I wanted to have, based on the standard ‘Page’ template for the Theme.

Modify the Template

In a similar way to that detailed above, I replaced the call that normally puts the page content with a call to a WordPress routine that displays links.

<?php 
/* 
Template Name: Think Tanks 
*/ 
?>
<?php get_header(); ?> 
<?php get_sidebar(); ?> 
<div class="main-content">
    <div class="entry"> 
	<h2>Think Tanks</h2>    
<?php get_links(10, '<li>', '</li>', '<br />', FALSE, 'name', TRUE, FALSE, -1, TRUE, TRUE); ?>
    </div> 
     
    </div> 
<?php get_footer(); ?>

The first parameter of the get_links call – in this case 10 – is the ID of the category of links that you want displayed on this page.  That’s why I suggested you write those Category IDs down…

Done!

And that’s it – you can add some static text to the page, but be aware that the links will be in a single long list.

This particular page is seen in action here, at CommunityNet.