WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] if (is_category) and wp_list_bookmarks array? (7 posts)

  1. Hello,

    I've got 50 categories (and a corresponding 50 link categories) and I'm wondering if there is an easier way to show the links in a link category on just that category page rather than run 50 variations of this code string in the sidebar:

    <?php if (is_category('idaho')) { wp_list_bookmarks('title_li=&categorize=0&category_name=idaho'); } ?>

    Is it possible to do some sort of an array? Or is there an even easier way?

    My dog thanks everyone.....

  2. MichaelH
    Member
    Posted 5 years ago #

    Try this:

    <?php
    if ( is_category() ) {
    $cat = get_query_var('cat');
    $category=get_category($cat);
    wp_list_bookmarks('category_name='.$category->cat_name); } ?>
    }
    ?>
  3. That works great - just what I need. Thanks! The next thing I need to learn is how to use Javascript (or ideally jQuery to keep from reloading the page) to be able to select categories from a drop down list and show the bookmarks for that category without going to that category page; so I may be back soon if I hit a brick wall with trying to learn.... - Mark

  4. That works great, but now I find another issue. I'd like to have those lists of bookmarks of single categories on pages other than category pages, specifically archive and single post pages.

    What I'm doing is feeding different sidebars to home, category, archive, single, search and search result pages with if and elseif conditionals in the sidebar. Those conditionals get me different text and the bookmark lists for each category on that category page.

    But in order to get a bookmark list on a single page from the archives, I need to be able to pull the category number from a single page in order to display a list of links to charities for that category, which is one of the fifty states.

    I looked into using custom fields and took a stab modifying the php above, but no luck.

    Also, sometimes a single page has a category URL; don't know if that is a further complication or indicative of a solution.

    Some pointers would be appreciated... Thanks

  5. I figured it out:

    <?php $category=get_the_category($cat); wp_list_bookmarks('category_name='.$category[0]->cat_name); ?>

    will find the category of a single page or an archives page and show the title of the category and the category links of that same name.

  6. mircury777
    Member
    Posted 5 years ago #

    Right now on post categories that don't have a corresponding bookmark category with links, simple outputs every bookmark... which I don't want.

    How would I check first to see if there is a corresponding category before outputting a links list.

  7. Don't know; I'd start a new thread with that question because this thread is marked "resolved."

Topic Closed

This topic has been closed to new replies.

About this Topic