Upgrading WordPress tags

Filed under: Blogging, WordPress — kathyjay at 5:33 pm on Tuesday, September 23, 2008

A while ago I noticed that the Blogroll had disappeared from this blog. As with so many things during my final months at my previous job, I just didn’t have time to dig through the WordPress documentation to find out why.

Today I did some nosing around and discovered that the old WP tags to generate the blogroll had been deprecated and removed a while ago. Hence the non-working blogroll.

One of the nice things about WP is the resources out there documenting how all the nuts and bolts work. If you really wanted to, you could customise WP to run an entire, complex website and not just a simple blog like this.

I came up with the new wp_list_bookmarks tag that was needed to replace the old code. Part of me sighed at the idea of upgrading to break people’s blog templates, but another part of got a little excited about the fact that this would be much easier than my old code.

To demonstrate, here is the old code:

<?php
$link_cats = $wpdb->get_results(
"SELECT cat_id, cat_name FROM $wpdb->linkcategories");
foreach ($link_cats as $link_cat) {
?>
<li id="linkcat-<?php echo $link_cat->cat_id; ?>">
<h3><?php echo $link_cat->cat_name; ?></h3>
<ul>
<?php get_links($link_cat->cat_id, '<li>', '</li>', '',
FALSE, 'name', FALSE); ?>
</ul>
</li>
<?php } ?>

Using the new WP tag, I have one line of code:

<?php wp_list_bookmarks('title_before=<h3>&title_after=</h3>'); ?>

It does essentially the same thing, only much less wordy. The wp_list_bookmarks tag defaults to ordering by name (something that had to be specified in the get_links tag) and retrieving all the categories. The one frustration is that it defaults to putting the category names in H2 tags, but that’s what the title_before and title_after parts of the argument do - change that behaviour to H3 tags so that I don’t have to re-jig the CSS.

WordPress has its negatives (the frequency that you have to upgrade and the time it takes to do the upgrade being the biggies) but it does have some nice features hidden under the bonnet. I’m not sure that anyone could use them if they don’t have at least a basic understanding of PHP first, though!

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>