tags:

views:

14

answers:

1

I use the following code to highlight a menu item if the post is in this category or the category is selected:

<a href="/category/presets/photoshop_actions" title="Only Photosshop Actions"
        <?php if (is_category(photoshop_actions) || is_single() && in_category('47')) {
            echo ' class="rounded rounded_active" ';}
            else{
            echo ' class="rounded" ';}  
        ?>
        >
        <span>
            Photoshop Actions
        </span>
    </a>

So here is the deal: I also want to have the rounded_active class set if there has been performed a search in the category - lets say the url looks like this when the search has been performed: http://localhost:8888/?cat=47&amp;s=boats How do I expand the code above to check if category with id 47 is part of the search query and then echo back

class="rounded rounded_active"
+1  A: 
<?php $active = is_category('photoshop_actions') || in_category(47) || get_query_var('cat') == 47; ?>

<a href="/category/presets/photoshop_actions" title="Only Photosshop Actions" class="rounded<?php echo $active ? ' rounded_active' : ''; ?>">
    <span>Photoshop Actions</span>
</a>

The PHP statement within the class attribute is a shorthand if.

I also kept the main logic outside of the HTML to keep things a little neater.

TheDeadMedic