WordPress.org

Ready to get started?Download WordPress

Forums

How to show link category (7 posts)

  1. CraigHartel
    Member
    Posted 9 years ago #

    I'm not understanding something with get_links in sidebar.php.

    Here is the line from the file:
    <?php get_links('-1', '<li>', '</li>', '<br />','','category',FALSE); ?>

    How do I get it to show the link category? Right now they are all showing up as a single list, although they are indeed sorted by category.

    I'm using WP 1.51 alpha and the Rin template.
    Thanks for your help.

  2. CraigHartel
    Member
    Posted 9 years ago #

    Oh, duh.

    Use get_links_list instead of just get_links and all is well. Thank you Codex.

  3. Mark (podz)
    Support Maven
    Posted 9 years ago #

    Best thing to do is ignore that tag ?
    <ul>
    <li id="here">Here
    <ul><?php wp_get_links(11); ?></ul>
    </li>

    The number in (brackets) is the Cat ID and doing it this way not only gives you separated categories, but you ALSO get to order the categories in any way you want, AND if you use 3 columns you can display different cats across the columns AND (yes, there's more!) this way also allows for full and easy CSS control.

    You know it makes sense ;)

  4. iand
    Member
    Posted 9 years ago #

    Or wp_get_linksbyname('cat name'), so you don't have to remember which category is number 11.

  5. CraigHartel
    Member
    Posted 9 years ago #

    Thanks, guys. I'll have to mess with those later, as it's nearly time to head to work.

  6. ianmcn
    Member
    Posted 8 years ago #

    I couldn't ignore the get_links tag as I needed a way to display all links plus categories and descriptions on the main links page (using get_links_list) but on the front page I only wanted 2 categories and no descriptions - using get_links achieved this, but as Craig pointed out it doesn't display categories - I finally came up with the following:

    <?php
    $link_cats = $wpdb->get_results("SELECT cat_id, cat_name FROM $wpdb->linkcategories WHERE cat_id=1");
    foreach ($link_cats as $link_cat) {
    ?>
    <li id="linkcat-<?php echo $link_cat->cat_id; ?>"><?php echo $link_cat->cat_name; ?>

      <?php get_links($link_cat->cat_id, '
    • ', '
    • ', '', FALSE, 'url', FALSE); ?>

    <?php } ?>

    repeat the above for each category you wish to show, changing "WHERE cat_id=1" to the relevant category. Not sure if this is the most elegant solution, but it works!

    For an update to WP, can we have a parameter on link categories for show_on_sidebar or something like that? It would make it a lot more versatile

  7. frank303
    Member
    Posted 8 years ago #

    Yes! Thank you this works perfect for me, i also just wanted to display only one category, with the category title and the links!
    Great!

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.