WordPress.org

Support

Support » How-To and Troubleshooting » links on the sidebar by categories

links on the sidebar by categories

  • Hi,
    I used a template in which the links are not “in categories”
    Here is the code as written in sidebar.php:

    <h3><?php _e('Ressources'); ?></h3>
    <ul>
    <?php get_links('-1', '<li>', '</li>', '', 0, 'name', 0, 0, -1, 0); ?>
    </ul>

    I want to have my links displayed in different categories like the default template.
    I tried to add this:
    <?php get_links_list(); ?>
    you can see the result on the blog (2 categories: blogroll and histoire) :
    http://artis-factum.com/

    Can someone please help me to fix this?
    Thanks.

Viewing 7 replies - 1 through 7 (of 7 total)
  • Try this:

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

    I tried this, it ave the same result as <?php get_links_list(); ?>

    Moderator James Huff

    @macmanx

    Let’s try this:

    First, we are going to assume that Blogroll is link category 1, and Histoire is link category 2. You can discover the actual IDs of each link category by going to Links/Link Categories.

    Now, replace what you have entered into the sidebar with the following, remembering to substitute the actual link category IDs:

    <h3><?php _e('Blogroll'); ?></h3>
    <ul>
    <?php wp_get_links(1); ?>
    </ul>

    <h3><?php _e('Histoire'); ?></h3>
    <ul>
    <?php wp_get_links(2); ?>
    </ul>

    Thank should do it, good luck.

    It works fine!
    Thanks a lot guys! Fast and efficient!

    That was quite helpful. Thanks.

    Hello,

    from my understanding ‘<?php wp_get_links(id); ?>’ is the trick to get all the links from a specific category, but it does not report the category name associated with.
    While ‘<?php get_links_list(); ?>’ does it, but will list all the categories.

    I was wondering if there was a way to get the category name automaticaly from WP when you select a category ID?

    If I’m correct the code provided by Macmanx means that you have to type manualy the category name each time (wich is indeed a working solution).

    I’m wondering what modifications are to be done on the code given in the codex and reproduced above by Marc to do the same?

    Not knowing PHP, I have tried to modify it for a single category but without success. I don’t know what parameter to use.

    Thanks.

    Hi all– I tried doing what macmanx suggested above, and it didn’t work (I got a “parse error” message on the sidebar instead.

    Here is the code relating to my links in my sidebar.php page as it stands now:

    <?php if( is_home() || is_page() ) { ?>
    <li id=”links”><?php _e(‘Links’); ?>

      <?php get_links(-1, ‘

    • ‘, ‘
    • ‘, ‘
      ‘, FALSE, ‘category’, FALSE, FALSE, -1, TRUE); ?>

    I have 3 categories of links, and the code above is just tossing them all into one entitled “Links”. Any suggestions?

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘links on the sidebar by categories’ is closed to new replies.
Skip to toolbar