WordPress.org

Ready to get started?Download WordPress

Forums

Need HELP writing a category classes if statement (3 posts)

  1. pshero
    Member
    Posted 3 years ago #

    Ok gang, trying this a different way and think I'm almost there but somewhere in this code is a problem that I can't find... or maybe I've just been staring at it too long.

    I'm classing posts based on category or category parent which are set from the theme admin. Should be pretty obvious what's going on here, but please ask if you've got a question:

    <?php
    // SET CLASSES FOR DIFFERENT POST TYPES PER CUSTOM OPTIONS //
    $photocat = get_option('woo_photography_category');
    $quotecat = get_option('woo_quotation_category');
    $quotecatID = get_cat_ID( $quotecat );
    
    if (get_categories('child_of => $photocat', TRUE)) {
        $mycat = "photograph";
    }
    elseif (get_categories('in_category => $quotecatID')) {
        $mycat = "quote";
    }
    else {
        $mycat = "post";
    }
    ?>

    I'd then just pull a 'class=<?php $mycat ?>" wherever it was needed.

  2. esmi
    Forum Moderator
    Posted 3 years ago #

    Assuming that this is within a Loop:

    <?php
    // SET CLASSES FOR DIFFERENT POST TYPES PER CUSTOM OPTIONS //
    $photocat = get_option('woo_photography_category');
    $quotecat = get_option('woo_quotation_category');
    $quotecatID = get_cat_ID( $quotecat );
    $photocatID = get_cat_ID( $photocat );
    
    if (in_category( $photocatID ) ) $mycat = "photograph";
    elseif (in_category( $quotecatID) ) $mycat = "quote";
    else $mycat = "post";
    ?>
  3. pshero
    Member
    Posted 3 years ago #

    Almost ESMI, the key problem here is that I need to check to see if the post category is IN or a CHILD of the woo_photography_cateogry so that all the child photography categories are treated just like the parent... any thoughts on how I'd modify for that?

    Tanks so much for the help!

Topic Closed

This topic has been closed to new replies.

About this Topic