Support » Fixing WordPress » Need HELP writing a category classes if statement

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

Viewing 2 replies - 1 through 2 (of 2 total)
  • esmi

    (@esmi)

    Forum Moderator

    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";
    ?>

    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!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Need HELP writing a category classes if statement’ is closed to new replies.