WordPress.org

Ready to get started?Download WordPress

Forums

if ONLY is category and if is PLUS category (3 posts)

  1. salromano
    Member
    Posted 1 year ago #

    Hi, all. Hoping you could help me out.

    I'm trying to to create a category sub-sorter without having to apply a million ifs for each category. I've managed to get it somewhat working, however, it's nowhere near where it should be.

    To achieve what I need to achieve, I need a way to turn this:

    <?php if (in_category('CATEGORY NAME')) { echo " class=\"current\"";}?>

    Into these two:

    <?php if (is_category('SOLELY CATEGORY NAME')) { echo " class=\"current\"";}?>

    <?php if (in_category('CATEGORY NAME + SECOND CATEGORY NAME COMBINED')) { echo " class=\"current\"";}?> (e.x.: http://site.com/category/category-name+second-category-name)

    How do I do this?

  2. Andrew
    Forum Moderator
    Posted 1 year ago #

    Is this what you're looking for

    if (get_category_by_slug('CATEGORY NAME')){}
    if (get_the_category_by_slug('CATEGORY NAME) && get_the_category_by_slug('SECOND CATEGORY NAME COMBINED)){}

    Referred from http://codex.wordpress.org/Function_Reference#Category.2C_Tag_and_Taxonomy_Functions

  3. salromano
    Member
    Posted 1 year ago #

    Not exactly.

    This is what I'm trying to do:

    http://i.imgur.com/Jn4Ei.png

    I've managed to get the top part done. I'm using category pages to accomplish this. If you're on the "Cat 3" category page, for example, "Cat 3" will be black as it's the current category.

    However, I can't seem to work the bottom bit. If you're on "Cat 3" and want to see posts limited to only the categories "Cat 3" and "Topic 1," you should be able to click "Topic 1," which would then turn black, and only see posts that are both in "Cat 3" and "Topic 1." (Together at the same time, I mean. Each post must have both categories attached.)

    [ Please do not bump, that's not permitted here. ]

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags