WordPress.org

Ready to get started?Download WordPress

Forums

links on the sidebar by categories (8 posts)

  1. sam67
    Member
    Posted 9 years ago #

    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.

  2. Marc
    Member
    Posted 9 years ago #

    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>

  3. sam67
    Member
    Posted 9 years ago #

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

  4. 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.

  5. sam67
    Member
    Posted 9 years ago #

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

  6. Brooks
    Member
    Posted 9 years ago #

    That was quite helpful. Thanks.

  7. Kowalsky
    Member
    Posted 9 years ago #

    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.

  8. adrock
    Member
    Posted 9 years ago #

    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); ?>
  9. I have 3 categories of links, and the code above is just tossing them all into one entitled "Links". Any suggestions?

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.