Create a Blogroll Page
Posted on August 29, 2007
Filed Under WordPress Coding, WordPress Customization |
Most WordPress themes put blogroll (a list of links) in the sidebar. This is fine if you only have less 10 links in your blogroll. But when your blogroll grows, the list can be very long, thus it’s no good to display it in the sidebar. In this case, the solution is to create a separate blogroll page, which is easy to do.
First, create a template PHP file in the theme directory. For my blog, I created a file called “links.php” in “\wp-content\themes\modernpaper-10″ directory so that I can add a blogroll page in the theme I am using (modernpaper).
At the beginning of the file, name the template. I named my template as “links”, thus I have code as:
<?php
/*
Template Name: Links
*/
?>
Then, just copy the codes from the page.php file, which is the default page template.
Inside the content division, add the following code to display the blogroll link list:
<ul>
<?php get_links(-1, ‘<li>’, ‘</li>’, ‘ - ‘); ?>
</ul>
Create a new page called blogroll or what ever you want to call.
Select “Links” as the Page Template from the dropdown list.
Publish the new page.
That’s it.
Here’s the entire code from my template file:
<?php
/*
Template Name: Links
*/
?>
<?php get_header(); ?>
<div id=”content”>
<div id=”contentleft”>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<h1><a href=”<?php the_permalink() ?>” rel=”bookmark”><?php the_title(); ?></a></h1>
<?php the_content(__(’Read more’));?><div style=”clear:both;”></div>
<?php endwhile; else: ?>
<p><?php _e(’Sorry, no posts matched your criteria.’); ?></p><?php endif; ?>
<?php posts_nav_link(’ — ‘, __(’« go back’), __(’keep looking »’)); ?>
<ul>
<?php get_links(-1, ‘<li>’, ‘</li>’, ‘ - ‘); ?>
</ul>
</div>
<?php include(TEMPLATEPATH.”/l_sidebar.php”);?>
<?php include(TEMPLATEPATH.”/r_sidebar.php”);?>
</div>
<!– The main column ends –>
<?php get_footer(); ?>
Comments
Leave a Reply