Listing links
WordPress is using three main functions to list links:
<?php wp_get_links(category); ?>displays links assigned to category which ID is stated within function. So<?php wp_get_links(5); ?>will show all links from category with ID #5.<?php get_links_list('order'); ?>displays links sorted by link category ID or name<?php get_links(category, 'before', 'after', 'between', show_images, 'order', show_description, show_rating, limit, show_updated, echo); ?>has the widest range of parameters. It also sorts links according to their category ID but offers much more features.
I wanted to create links lists which would allowed me to display two categories (’How To’ and ‘Everything About’) in the sidebar and the third category (’Plugins’) on a separate page.
Links in sidebar are pulled by <ul><?php get_links_list('name'); ?></ul> . That gives a list of ALL links which wasn’t my idea. I ‘ve tried to use <ul><?php wp_get_links('12'); ?></ul> and I got list of links from pointed category but bullets assigned to unordered list were missing ;) . Finally I’ve put <ul><?php get_links('12', '<li>', '</li>'); ?></ul> function which allowed me to display all links from one category as an unordered list. I repeated that function with the other ID number to list links from the second category.
Now only page left. NigaRila theme has built-in page-links.php template.
It’s main part looks like that:
<div class="post">
<h2 class="post-title"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link: <?php the_title(); ?>"><?php the_title(); ?></a></h2>
<p class="post-info">Created on <em><?php the_time(’M d Y’); ?></em> <?php edit_post_link(); ?></p>
<div><ul><?php get_links_list(’name’); ?></ul></div>
</div>
That also gives a list of ALL links. And there is no plain text being displayed!
First of all I replaced content with the one from regular page which includes displaying posts (if there are any) with author and date info as well as the comment template and page navigation. And then I replaced
<div><ul><?php get_links_list('name'); ?></ul></div>
with
<ul><?php get_links('5', '<li>', '</li>', ' » '); ?></ul>.
This function allowed me to display ALL links from category ‘Plugins’ as an unordered list with special character » between link and its description.
And now I have it exactly I wanted :D .
18th August 2007 3 comments





This is exactly what I needed! Thank you! Will
# displays links sorted by link category ID or name
So how would you order it according to id? I want my links to display in chronological order, with the most recent links first. I would also like only the most recent 10 links.
I tried this:
But that doesn’t work at all. I also tried a number of variations using wp_get_links and wp_list_bookmarks
This plugin might work: http://wordpress.org/extend/plugins/my-link-order/
…but I would like to learn how to do it myself.
http://codex.wordpress.org/Template_Tags#Link_tags
Hi Mike,
You can limit number of links displayed using *limit* parameter.
. Can you post it again, please?
On WP Codex:
» http://codex.wordpress.org/Template_Tags/get_links
you will learn how to:
- apply parameter *limit*
- how to order links according to ID (although I have written about it above)
- and how to use reverse order that will let you display links chronologically starting with the most recent one.
I don’t know what have you tried because this part of your comment is missing