PureNews

PureNews is an amazingly sleek and powerful news theme with unlimited color variations.

View full feature list Check out the live demo Buy this theme today

Page Templates – Create a Links Page

Posted by on 11th May 2008 WordPress Coding & Design 13 comments

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

[sourcecode language='php']/*
* Template Name: Links Page
*/[/sourcecode]

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.

[sourcecode language='php']

    < ?php wp_list_bookmarks('title_before=

    &title_after=< /h3>‘); ?>

[/sourcecode]

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:

[sourcecode language='php']< ?php
/*
* Template Name: Links Page
*/

get_header(); ?>

< ?php if (have_posts()) : while (have_posts()) : the_post(); ?>

A PHP Developer using WordPress to power both blogging and commercial CMS sites. I've written and released a couple of plugins for WordPress and am currently writing plugins for use on commercial websites.

13 comments - Leave a reply
  • Posted by Dean Saliba on 11th May 2008

    Very interesting, I've seen blogs with sidebars that are easily three or four times longer than page content!

  • Posted by David Shaw on 11th May 2008

    I am currently looking at how to do my blog roll, and have considered using a links page.

    Great Advice

  • Posted by chase on 11th May 2008

    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.

  • Posted by sachin on 11th May 2008

    Thanks for this great advice!

  • Posted by Sarah on 11th May 2008

    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).

  • Posted by Monika Mundell on 12th May 2008

    Thanks to you Sarah I already have this :razz: It works a treat.

  • Posted by Sarah on 12th May 2008

    Glad to hear it Monika. Now you understand how it was done! ;)

  • Posted by Budhi on 13th May 2008

    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.

  • Posted by Kaza on 13th May 2008

    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.

  • Posted by Anke on 18th Sep 2008

    Thank you! I finally managed to get rid of the tag for category names.

  • Posted by SonDan on 24th Apr 2011

    I know I might sound a bit dense, but part of some parts of the instructions were clear as mud to me since I am not too deep into coding.

    My question is can just put this code in my custom php file and then the new template will show up when I open "Add New Page" from the WordPress Dashboard? And then will the links automatically show up in that page for me to save? Or have I over-simplified this task.

    I would love to have a link page because I had tp created one using HTML and it is very time consuming to change whenever I add or delete a link.

    Thanks in advance for reading and trying to clarify for me.
    My recent post Max Mathews- Pioneer in Making Computer Music- Dies at 84