The power of WordPress ‘Links’

in Code no responses

Ello ello, what’s all this then?

WordPress links does exactly what it says on the tin, it displays links in your wordpress template whether its widgetized or not. But there’s so much more that the built in ‘Links’ functionality can do. In this article we will look at how the ‘Links’ functionality can be used to help make your life easier and do the same things that bespoke plugins have be made too do.

I’ve Got The Power!

Or more precisely WordPress has the power. We’ve all seen different hacks, workarounds and general hickory pokery used to show off the expandability of WordPress, so what I’m about to show isn’t anything special. In fact there will be no hacking or workarounds and most definitely no hickory pokery in this article; all we will be doing here is using the WordPress API to the advantage of the user i.e you.

Get To The Point!

Or more importantly the code. What i’m about to show you is a very basic use of the wordpress ‘Links’ but hopefully those einsteins among will think of better uses than this. I’m going to show you how to create a ‘Currently Reading’ widget (like the one in my sidebar) that will show the name of the book and a description of the book. This is easy enough to work out how to do if you read the WordPress Documentation but I thought I would share how I did it.

In the latest version of WordPress the wp_list_bookmarks() function is used to call the bookmarks/Links and display them on the page so this is what were going to be using.

Here is the code used in the sidebar:

<?php wp_list_bookmarks('category_before= //The text that goes before each category. Defaults to <li id="[category id]"> 
&category_after= //Text that goes after each category. Defaults to </li>
&category_name=Currently Reading //The name of the category
&show_images=0 //Display an image (in this case book cover).1=true 0=false&show_description=1 //display description.
&orderby=updated //Order it by the last updates bookmark
&title_before=<h4> //what goes before the title
&title_after=</h4> //what goes after the title
&show_name=1 //show the text link
&between=<br /> //Text to place between each bookmark/image and its description. Defaults to '\n' (newline).
&before=<p> //Text to place before each bookmark. Defaults to '<li>'.
&after=</p> //Text to place after each bookmark. Defaults to '</li>'.
&title_li=0 //Text for the heading of the list
&categorize=0 //Bookmarks should be shown within their assigned Categories or not.
'); ?>

It should be noted that this code has been formatted for display reasons. This is how the code should be entered:

<?php wp_list_bookmarks('category_before=&category_after= &category_name=Currently Reading&show_images=0&show_description=1&orderby=updated&title_before=<h4>&title_after=&show_name=1&between=&before=&after=&title_li=0&categorize=0'); ?>

This has just been thrown into a text widget that I called currently reading. For the code to be executed in the text widget you will need the Exec-PHP plugin. You can read the documentation about wp_list_bookmarks() on the WordPress Codex. The only thing left to do is create a link category called ‘Currently Reading’ and add a bookmark with the name of your book, and image and a description, the plugin will do the rest.

Room For Improvement

This is a very simple and effective use of the WorPress links capability but there are many more ways to use this that more imaginative people could come up. If you liked this *cough* short article then why not leave a comment.


No Comments Yet


Have something to say?