Category Icon

This topic contains 2 replies, has 2 voices, and was last updated by  Karen Atherholt 9 years, 4 months ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #19589

    [http://visitroswellga.com/community-calendar/][1]
    I would like to show an image icon next to the event title of the event
    if the category=’christmas’ on the above linked url. Can this be done?

    Karen Atherholt
    #19597

    Yes, you can use has_term() to check if an event has a particular taxonomy term:

    <?php 
    if ( has_term( 'christmas', 'event-category', get_the_ID() ) {
         //event has category with slug 'christmas', display icon
    }
    ?>
    
    Stephen Harris
    #19601

    Thank you Stephen. It took me a while to make it work, but here is the final code I used in my custom file – shortcode-event-list.php

    <td valign="top"><!-- Is event category 'christmas' -->
    <?php 
    if ( has_term( 'christmas', 'event-category' )) {
        //event has category with slug 'christmas', display icon
        printf('<img src="http://visitroswellga.com/wp-content/uploads/2015/10/bow-icon.png" alt="Roswell Christmas Event" />' );
    }
    ?>
    </td>
    

    I use a plugin called “WP Custom taxonomy Image” (By Aftab Husain) in order to have a field to add the image icon to my category.

    Here are the results: http://visitroswellga.com/community-calendar/community/calendar-christmas-events/

    Karen Atherholt
Viewing 3 posts - 1 through 3 (of 3 total)
To enable me to focus on Pro customers, only users who have a valid license for the Pro add-on may post new topics or replies in this forum. If you have a valid license, please log-in or register an account using the e-mail address you purchased the license with. If you don't you can purchase one here. Or there's always the WordPress repository forum.