Support » Plugins » breaking up links categories

  • I’m new to WordPress and would like to be able to break the links categories into different positions.

    For example, the blog will have the main navigation links like the main page, but then I’d like to have the blogroll underneath categories and archives?

    Is this possible? Can someone please point me in the right direction?

    I’ve installed the widgets plugin to help with positioning different parts, but i can uninstall if it would be too much to do it with this plugin.

    I’m not a strong coder, but I have been able to change code in oscommerce and mambo/joomla, so I have a bit of experience.

    Thanks in advance for any help!

Viewing 9 replies - 1 through 9 (of 9 total)
  • Mark (podz)


    Support Maven

    Can we have a link to your page?
    If you could then describe precisely what you need then we’ll sort the answer 🙂


    I’d rather not give out the link because it’s far from ready…I hope that’s ok. Sorry.

    Is is possible to put structure the sidebar so that categories of links are in different positions?

    For example:
    – Link Category #1
    – Archives
    – Link Category #2 (Blogroll)

    Right now, when I “publish” Links, it puts them all together on the sidebar. I’d just like to be able to break them up or change the order.

    Does this post help?

    Add sections in your sidebar for each category and make a call to get_links_list() with that categories ID.

    Yes that helps. Thanks!

    Now…how do I put the <?php get_links_list(‘id’); ?> as a widget so I can just put them in the order I want?

    I’ve checked the Widget documentation and I just don’t know how… or should I just put it in the sidebar.php page? Or if I put it in the sidebar.php page does it show up in the Widgets on the Admin side?

    Sorry I’m still learning…

    If the theme you are using is not prepared for “widgets” that plugin will not work in your theme. (that’s when a link is handy to get fast and precise help)

    yes i understand…sorry didn’t mention which theme. I’m just using the default one, Kubrick I think it’s called?

    I already have widgets installed and working on the admin side…just wondering if I can make a simple widget that will call just one category of links. then i can make a couple and order them how i want to…

    ok…i tried to modify widgets.php and sidebar.php

    i put this in sidebar.php (around line 50)

    <?php get_links_list('1'); ?>
    <?php get_links_list('2'); ?>

    i put this in widgets.php (around line 640)

    ‘function widget_links_1($args)
    {// This ONLY works with li/h2 sidebars.

    function widget_links_2($args) {
    // This ONLY works with li/h2 sidebars.
    }<br />


    register_sidebar_widget(‘Main Nav’, ‘widget_links_1’);
    register_sidebar_widget(‘Blogroll’, ‘widget_links_2’);`

    at the bottom of the file.

    They showed up as Main Nav and Blogroll in the Widgets on the admin side, and I placed them in the first and third position…but when i view the site it shows both link categories (in reverse order) in both positions…weird.

    Can somebody help me make a widget that will call one link category that will work? what i’m doing isn’t working right…

    any ideas? should I just uninstall the widgets and code it into the sidebar.php?

    You were on the right track! The problem is that the function get_links_list() does not accept a link category ID number as a parameter.

    What I did was kind of a kludge for now, but it got me going.

    First, in links.php, I created a new function called get_single_links_list() that takes the link ID as a parameter:

    function get_single_links_list($order = 'name', $hide_if_empty = 'obsolete', $linkcategoryid) {
    global $wpdb;

    $order = strtolower($order);

    // Handle link category sorting
    if (substr($order,0,1) == '_') {
    $direction = ' DESC';
    $order = substr($order,1);

    // if 'name' wasn't specified, assume 'id':
    $cat_order = ('name' == $order) ? 'cat_name' : 'cat_id';

    if (!isset($direction)) $direction = '';
    // Fetch the link category data as an array of hashesa
    $cats = $wpdb->get_results("
    SELECT DISTINCT link_category, cat_name, show_images,
    show_description, show_rating, show_updated, sort_order,
    sort_desc, list_limit
    FROM $wpdb->links
    LEFT JOIN $wpdb->linkcategories ON (link_category = cat_id)
    WHERE link_visible = ‘Y’
    AND list_limit <> 0
    AND cat_id = $linkcategoryid
    ORDER BY $cat_order $direction “, ARRAY_A);

    // Display each category
    if ($cats) {
    foreach ($cats as $cat) {
    // Handle each category.
    // First, fix the sort_order info
    $orderby = $cat[‘sort_order’];
    $orderby = (bool_from_yn($cat[‘sort_desc’])?’_’:”) . $orderby;

    // Display the category name
    echo ‘ <li id=”linkcat-‘ . $cat[‘link_category’] . ‘”><h2>’ . $cat[‘cat_name’] . “</h2>\n\t

      // Call get_links() with all the appropriate params

    • ‘,”
    • “,”\n”,

      // Close the last category
      echo “\n\t


    Next, in widgets.php, around line 650 or so, I added a few blocks of code like this:

    function widget_links_2($args) {
    // This ONLY works with li/h2 sidebars.
    get_single_links_list('name', 'obsolete', 2);

    Notice that in the list of arguments, the “2” is the link category ID number. The modified function above accepts this number and modifies the database query to list only the single category.

    And at the end of widgets.php, I registered the widget:

    register_sidebar_widget('My Links', 'widget_links_2');

    It’s working great now!

    What I will do in the near future is modify the original get_links_list() function to take the category ID as an optional third parameter, rather than have the separate function for it. Being in a bit of a rush today, I don’t have time to tackle it, but for now I have it working.

    To create the new function, the only changes I made were to add $linkcategoryid as one of the parameters, which is the first line of my new function:

    function get_single_links_list($order = 'name', $hide_if_empty = 'obsolete', $linkcategoryid) {

    Then further down, in the queries, I changed this:

    WHERE link_visible = 'Y'
    AND list_limit <> 0

    by adding this just below it:

    WHERE link_visible = 'Y'
    AND list_limit <> 0
    AND cat_id = $linkcategoryid

    That’s it!

    Note that the word wrapping is killing my code here; hopefully my post makes some sense.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘breaking up links categories’ is closed to new replies.