WordPress.org

Ready to get started?Download WordPress

New get_links_list() function

Posted August 26, 2003 by Dougal Campbell. Filed under Development.

There is also a new function called get_links_list() but I’ll let Dougal explain that.

Oh, sure, put me on the spot. :)


/*
* function get_links_list()
*
* added by Dougal
*
* Output a list of all links, listed by category, using the
* settings in $tablelinkcategories and output it as a nested
* HTML unordered list.
*
* Parameters:
* order (default 'name') - Sort link categories by 'name' or 'id'
* hide_if_empty (default true) - Supress listing empty link categories
*/

You can see it in action on my in-testing version of my blog. All the links listed in the menu between the “Links:” heading down to the calendar were generated by a single line in my template that looks like this:


<?php
get_links_list('id');
?>

I’m telling it to sort my link categories by id, rather than by name, because I entered my categories into the sytem in a particular order that I wanted to use. The links under each category are sorted according to the options set in the Link Manager’s “Manage Link Categories” section.

This function is hardcoded to generate an HTML unordered list (<ul /> ) Maybe one day we’ll make a similar function that can generate the links with some different HTML formatting. But don’t count on it.

No Pings

RSS feed for comments on this post.

  1. Remember that you can style an unordered list to look like whatever you like, it doesn’t need to have bullets and all that. There are several threads in the forum that pertain to this.

    Comment from Matt on August 26, 2003

  2. I see that there’s a “listening to” on the example blog, what is that powered by?

    Comment from Michael on August 27, 2003

  3. I don’t get this, how does it differ from this?:

    Comment from Michael on August 27, 2003

  4. ARGH! Seems that using the CODE tag isn’t working. Let’s try it without:

    Comment from Michael on August 27, 2003

  5. Nope, okay let’s try this: get_links(4, '', '', '', 0, '_id', 0, 0, 10, 0 ) or get_links(4, ”, ”, ”, 0, ‘_id’, 0, 0, 10, 0 )

    Comment from Michael on August 27, 2003

  6. Sorry for all these posts, but it seems that this comments system is very bad at handling posts with HTML code in them :|

    The above have li /li as two of the options, essentially creating a list. So what’s the difference?

    Comment from Michael on August 27, 2003

  7. All the CODE tag normally does is to display its contents in a fixed-width font. You still have to escape ‘<’ characters as ‘&lt;’ if you want to show what code should look like.

    Anyhow, what’s different between get_links_list() and get_links() is:

    get_links() will not display the name of the link category, and will sort all of your links as one big list (unless you put a separate get_links() call in your template for each of your categories), regardless of the link category. It pretty much ignores all of the options you’ve set in the Link Categories management screens

    get_links_list() automagically honors all of the settings in the Link Categories screens, for each category individually. So it sorts the categories in the order you want (with a header for each one), and it sorts the links for each category separately.

    In my case, I have six categories (well, actually, I have seven, but I don’t have any links in the default ‘General’ category, so it isn’t displayed):

    Dougal’s Stuff
    Tangential
    Technology and Design
    Misc Stuff
    Blog Meta
    Tech News

    My Link Categories options have different settings for each category. In “Dougal’s Stuff”, I sort by link ID, and don’t display ‘updated’ info. The ‘Tangential” category is sorted by ID, but does display ‘updated’. In “Technology and Design”, I sort by updated/descending. The other three categories are all sorted by the link name.

    All of that sorting and the other display options are being automagically handled by get_links_list(). All I have to tell it is in what order I want the categories displayed. In my case, I have it list my categories by ID, because I entered the categories in a specific order that I wanted to use.

    Internally, get_links_list() is calling the get_links() function for you, passing it all the appropriate parameters to handle the options set in the Link Categories admin screen.

    Does that clear things up?

    Comment from Dougal Campbell on August 27, 2003

  8. Oh yeah, and my “What’s Playing” is handled by the What’s Playing Plugin for Winamp3. That site has some links to plugins for other players, too, and also to the PHP code to receive the info from the plugin.

    Comment from Dougal Campbell on August 27, 2003

  9. Ah, I get it. Nice!

    Comment from Michael on August 28, 2003

  10. I’ve asked this in b2’s feature request forum in the past, but had no response. So maybe I’ll ask here with some success. Could you please add a feature to get_links_list() sorted not by id nor name, but by the length of the name? For example, if you remembered slashdot’s old frontpage, the links on the left were listed with the shortest words first and last and the longest words in the middle. It makes for a more aesthetically pleasing list. Or, using another example, if you have a blogrolling account, one of the sorting options that blogrolling provides is to sort according to the size of the link (i.e. the link’s text name) — this option is listed under “Sorting Tricks” in the Preferences menu for your blogrolling.com account. In this way, instead of sorting by “id” or “name”, you can have sort by “wordlength,” in which case you’ll need an additional parameter such as “toplongest, bottomlongest, middlelongest, middleshortest” to describe the sorting method. This is one of the features, in my opinion, that will make wordpress more attractive to bloggers who take attention to details (details that matter).

    Comment from John on August 28, 2003

  11. First, the support forums would be a better place for this.

    But, I’ve just added the ability to sort link categories by name length.

    Comment from Dougal Campbell on August 28, 2003

  12. Yes, future tangentially related comments will be deleted. Please keep such matters to the support forums.

    Comment from Matt on August 31, 2003

  13. Sorry but I’m not that familiar with php some things are asy some are not and I’m the type that learns by example. I get what it does but can someone please post a complete example of the code they are using so I can see how this works.

    Comment from Maurice on September 26, 2003

  14. sorry i.e

    Comment from Maurice on September 26, 2003

  15. Dougal, this is an awesome little function. Thanks so much. :D

    Comment from Geof on October 16, 2003

See Also:

For more WordPress news, check out the WordPress Planet.

There’s also a development P2 blog.

To see how active the project is check out our Trac timeline, it often has 20–30 updates per day.

Categories

%d bloggers like this: