These days sidebars get so easily cluttered with recent posts, categories and tags, recent comments, top commentators etc. The list is endless. Throw in your blogroll and your sidebar can become longer than the page content!
Moving your blogroll into its own page can keep things neater and allow you to have a longer list that doesn’t clutter up your sidebar. The way to do this is with a page template.
Creating a Page Template
Your theme may or may not have a page.php file already in it. If it does then open this up and save it with a new name eg. links.php, if it doesn’t then open up index.php and save this with the name of links.php (your theme may already have a links template so you could just look at that or put it to one side and follow this post to try and create it for yourself). To then set this up as a new page template within WordPress you need to add the following after the opening PHP tag at the top of the page
/* * Template Name: Links Page */
This is how you define the file as a page template, and the template name will show up as an option in the Add/Edit Page page under Advanced Options and Page Template (this option only appears when there is one or more page templates available).
Then in the page scroll down to the point where you see the template tag the_content(). This tag is used to display the content supplied when you create your page, so you can keep this in if you want to give a brief intro to the page. There’s no harm in leaving it in there as it will not display anything if there’s no content to display.
List Your Bookmarks
We then use the wp_list_bookmarks() template tag which displays the links added via your Links Manager / Blogroll Manager in the admin section. Add the following code below the_content() tag.
<ul>
< ?php wp_list_bookmarks('title_before=<h3>&title_after=< /h3>'); ?>
</ul>
The tag accepts a number of parameters, the more popular are explained below:
- category
- A comma separated string of link category IDs of which to display, meaning you could have a category containing a selection of links that are not displayed for some reason (eg. you’ve got your favourite links to display in your sidebar, then all other links go in a second category to only be shown on your links page).
- title_li
- Sets the title of the bookmark list if needed (only used when category names are not being displayed).
- title_before
- Specify the tag or text to go before the category name. The default is <h2>
- title_after
- Specify the tag or text to go after the category name. The default is </h2>
- orderby
- Specify the order in which the links are displayed, defaults to the name, can accept a number of options such as id, rating, rand (random order).
If you want to allow comments on your page then you can leave the comments_template() tag in there if it’s there (or add it below the links list code). If you don’t want comments then remove it.
The Final Page Template
That should be all you need to do. Of course different themes may require additional markup to help keep the elements of the page in the correct place. The final template should look similar to the following:
< ?php
/*
* Template Name: Links Page
*/
get_header(); ?>
<div id="content">
<div class="entry">
< ?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div class="post" id="post-<?php the_ID(); ?>">
<h2>< ?php the_title(); ?></h2>
< ?php the_content(); ?>
<ul>
< ?php wp_list_bookmarks('title_before=<h3>&title_after=< /h3>'); ?>
</ul>
</div>
</div>
< ?php endwhile; endif; ?>
</div>
< ?php
get_sidebar();
get_footer();
?>
Page Templates have so many uses. They allow you to have code or content that isn’t seen in the page content editing area within the WordPress admin. Once you understand page templates you can really exploit the flexibility of WordPress in so many ways such as adding a contact page or displaying information from another database table such as a photo gallery (yes I know, WordPress 2.5 has a gallery option built in, but it’s quite limited), and much more.






















Dean Saliba | May 11th, 2008 at 11:28 am #
Very interesting, I’ve seen blogs with sidebars that are easily three or four times longer than page content!
David Shaw | May 11th, 2008 at 6:29 pm #
I am currently looking at how to do my blog roll, and have considered using a links page.
Great Advice
chase | May 11th, 2008 at 8:43 pm #
another possible idea is using a CSS dropdown menu on your main navigation for your blogroll. If looking to conserve space is an issue, that could be a good option for you.
sachin | May 12th, 2008 at 2:05 am #
Thanks for this great advice!
Sarah (Post Author) | May 12th, 2008 at 2:34 am #
Dean, I know what you mean. Add in a couple of years of Archives too and the sidebar can be way off. That’s why a lot of people opt for 2 sidebars these days.
David and sachin, no problem
chase - you’re right you could, but the main focus of the post was Page Templates, the links list is just the one page most bloggers would probably use and was less complex than a contact us page (which I’ll be doing at some point in the future too).
Monika Mundell | May 13th, 2008 at 2:55 am #
Thanks to you Sarah I already have this
It works a treat.
Sarah (Post Author) | May 13th, 2008 at 3:12 am #
Glad to hear it Monika. Now you understand how it was done!
Budhi | May 13th, 2008 at 8:40 pm #
Thanks Sarah for the tips, it gives me a new possible solution for my blog, I’ve been struggling to decide what items should/shouldn’t I put in my sidebar without makes it ridiculously long.
Kaza | May 14th, 2008 at 1:51 am #
I’m really new at this whole blogging thing. I really am Glad I found such a intresting website dedicated to helping others set up their blogs.
I like the idea of the side bar link. It’s gonna make the site cleaner looking.
Anke | September 18th, 2008 at 10:04 pm #
Thank you! I finally managed to get rid of the tag for category names.