WordPress.org

Ready to get started?Download WordPress

Forums

Separating Different Categories of Links (10 posts)

  1. JMPrice
    Member
    Posted 9 years ago #

    Hi, I just started up a new blog on http://culturespace.org.

    My question:
    Currently I have two categories of links: "Blogroll" and "Media".

    I would like to separate these two categories on my sidebar, but WordPress combines them.

    This is the code in my sidebar:
    <h2 class="sidebar-title">Blogroll</h2>
    <?php get_links('-1', '', '
    ', '
    ', 0, 'name', 0, 0, -1, 0); ?>

    How do I get it to call for only one category?

    Thanks,

    Joe

  2. iand
    Member
    Posted 9 years ago #

    <?php wp_get_linksbyname('link cat name here'); ?> should do the job.

  3. Mark McKibben
    Member
    Posted 9 years ago #

    The -1 at the beginning of the parameters in get_links tells WP to grab the links from all categories. Go into WP's Link Manager and check what the category ID is for your Blogroll & Media categories. Then replace that line with something like this:
    <h2 class="sidebar-title">Blogroll</h2>
    <?php get_links('0', '', '
    ', '
    ', 0, 'name', 0, 0, -1, 0); ?>
    <h2 class="sidebar-title">Media</h2>
    <?php get_links('1', '', '
    ', '
    ', 0, 'name', 0, 0, -1, 0); ?>

    The Codex covers this under Template Tags/get links.

  4. JMPrice
    Member
    Posted 9 years ago #

    Manzabar, you are brilliant and quick. Thank you.

  5. Mark McKibben
    Member
    Posted 9 years ago #

    Nah, the brilliant one is whoever wrote up the excellent article in the codex. I've just been riding on their coattails. :)

  6. Root
    Member
    Posted 9 years ago #

    You could do it in CSS by applying the relevant selector for link cats. No php necessary.

  7. Mark McKibben
    Member
    Posted 9 years ago #

    From looking at WP 1.5 classic theme, it looks like one can do something similar with just <?php get_links_list(); ?> and some CSS styling as Root suggested but if you have more link categories and you don't want them all appearing in your sidebar*; then I'd stick with what I described above.

    * As an example, I've been working on a theme for 1.5 for my eventual upgrade and I'm storing the links for the theme's navbar in WP's Link Manager. I wouldn't want those links to show up with the rest of the links in WP's Link Manager so using get_links_list() wouldn't work for me.

  8. Root
    Member
    Posted 9 years ago #

    Well the question was how to separate - not to only show one :)

  9. Mark McKibben
    Member
    Posted 9 years ago #

    @Root: Good point. I guess I've used this trick often enough that it's my hammer solution (so every problem is looking like a nail to me). :)

  10. Root
    Member
    Posted 9 years ago #

    I have got the greatest admiration for the php gurus who spend time helping people here. I always try the simple solution myself. Its usually all I can manage :)

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.