Adding Link Manager Tags to Your WordPress Templates

It's fairly common — well, almost universal — to feature links to your friends’ blogs in a sidebar of your own blog. And, WordPress has a “Links Manager” which makes this even easier (if you’re already running WordPress, you can get to this via the “Links” option across the top of the admin interface). The Link Manager provides an interface for adding and categorizing links; you can set display properties for each category, including how many links to display, whether to display a description, and how to sort the links (such as by name or even random order).

Say you want to add a blogroll to your site. There’s already a “blogroll” category by default and you can add or delete links as you like. Then, it’s just a matter of adjusting your templates to display the links in your sidebar. Now, depending on which theme you're using, this may happen automatically. But, if not, it’s not hard to edit your templates to have it do that.

The WordPress wiki lists plenty of Links Manager-related tags (well, five tags, but you might think that there’d be only one, “display links” or something). They’re actually very similar, and are largely separated based on whether they follow the settings in the Link Manager or whether they override those settings, and whether you need to specify the output-category by-name or by-category-number.

  • get_links_list — This disregards the settings in the Link Manager and displays links from a number-specified category.

  • wp_get_links — This follows the settings in the Link Manager and displays links from a number-specified category.

  • get_links — This displays links from a number-specified category and allows the user to customize the output of the tag.

  • wp_get_linksbyname — This follows the settings in the Links Manager and displays links from a name-specified category.

  • get_linksbyname — This displays links from a name-specified category and allows the user to customize the output of the tag.

Unless you’re using a PHP-based code to feed numbers in, it’s probably easiest to make use of the tags which support categories specified by name. So, I’ll focus on the two tags which support name-based category references (“wp_get_linksbyname” and “get_linksbyname”). And, chances are, you’ll want to go along with the settings which you applied in the Links Manager, so you can use “wp_get_linksbyname” for that.

To make use of that, just open up your sidebar file (sidebar.php) and add a reference to that line, enclosed in <ul></ul> tags. Assuming that the category you wanted to display was “Blogroll”, the code could look something like this:

<?php wp_get_linksbyname('Blogroll') ?>

You may also want to add an additional header above that as that code only produces the list itself. You can follow along with the surrounding code within your sidebar.php — it’s probably an <h2></h2> tag or such. That’s it — just upload your new sidebar.php to your appropriate theme directory.

Footnote: Apparently — if you’re using get_linksbyname — you can set a parameter so that it includes each link’s update time next to the link (based on its most recent ping to Ping-o-Matic). And, if you set the sorting to [last] updated, you can have your friends’ blogs listed in the order that they updated along with the time that they updated.

This all sounds nifty, but I haven’t had any luck getting that to work. I tried the no-www fix and I manually ran /wp-admin/update-links.php, but I just couldn't get the update-times to show up. So, I’m just making use of a random listing for now. But, I’m open to any ideas there.

3 thoughts on “Adding Link Manager Tags to Your WordPress Templates

  1. This is completely off topic but is this the alex who is into the “gothenburg” metal sound?? Cuz i am infatuated with the whole swedish scene…Anyway do you play any instruments?..

  2. Hi Stephen! Indeed, I am the Alex who enjoys the “Gothenburg” sound :). I suppose it’s not really on topic for this post, but I’ll send you an e-mail about that.

  3. […] In WordPress lassen sich beliebig viele Links im Linkmanager verwalten. Die Links können in verschiedene Kategorie eingeteilt werden, die dann entsprechend gruppiert ausgegeben werden können. Die Ausgabe-Funktionen sind meiner Meinung nach aber nicht ganz so optimal. Die verschiedenen Ausgabe-Funktionen sind hier sehr gut beschrieben, ebenso in der offiziellen Dokumentation. Was aber fehlt ist eine Funktion, die alle Links genau so ausgibt wie sie definiert sind. Warum gibt es denn die Möglichkeit eine Formatierung anzugeben, wenn diese dann nicht genutzt wird? Ich möchte nicht jede Kategorie einzeln ausgeben müssen, nur damit die Formatierung beachtet wird. Um mein Ziel zu erreichen musste ich in der entsprechenden Funktion (get_links_list) nur zwei Zeilen verändern: […]

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.