• Resolved amulet

    (@amulet)


    I posted about this before, but I was late replying to the person who replied, so I am trying again. I have a links page, where I want all the links and all the categories to show, with the links displaying in alphabetical order under each category, but I also want to list links in the sidebar, only I want to limit how many display under each category (and may want to limit categories). I want those links to display in random order under each cat, although I’m not stuck on that, if it can’t be done with everything else I want to do. I’ve tried adjusting the settings in admin, but that, of course, affects both instances of get_links_list. Can I make it display one way in one file and a different way in another? I’ve tried other options like wp_get_links, but nothing seems to work. The only thing I can figure to do it is to use the template tag which lets me set it so it shows only one category (I forget if it’s wp_get_links or what at the moment), and do that for every category I want shown in the sidebar, and setting options in the code. But that would be tedious and way too much trouble. Thanks.

Viewing 2 replies - 1 through 2 (of 2 total)
  • “I was late replying to the person who replied, so I am trying again.”

    New one on me…

    get_links() (or wp_get_links()) could be set to display a limited number of links randomized, but you wouldn’t be able to organize under category. For that you’ll have to set up a custom query that collects the link categories, then loops through the use of get_links on each:

    <ul>
    <?php
    $exclude_cats = array(1, 10);
    $linkcats = $wpdb->get_results("SELECT cat_id, cat_name FROM $wpdb->linkcategories ORDER BY cat_name");
    foreach($linkcats as $linkcat) {
    if(!in_array($linkcat->cat_id, $exclude_cats)) {
    echo "<li><h2>$linkcat->cat_name</h2><ul>\n";
    get_links($linkcat->cat_id, '<li>', '</li>', '', 0, 'rand', 0, 0, 10, 1, 1);
    echo "</ul>\n</li>\n";
    }
    }
    ?>
    </ul>

    This limits links listed under each link category to 10, and randomizes the list. Use the $exclude_cats array to set which link categories to…exclude.

    Thread Starter amulet

    (@amulet)

    That seems to be working! Thank you so much!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘get_links_list on Links Page vs. Sidebar’ is closed to new replies.