Display default text depending on category

Home Forums Calendar Products Events Calendar PRO Display default text depending on category

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #1002592
    jmegordon
    Participant

    Hi,

    I was looking to display a default paragraph of text after the content each event, dependent on the category it is displayed in.

    I’ve tried adding the following code to my single-event.php file, but it only seems to display the ‘else’ text.

    Does anyone have any ideas how to fix this?

    #1002706
    Nico
    Member

    Hi Gerry,

    Thanks for reaching out to us! Hopefully I can help you out on this 🙂

    Can you try changing is_category to has_category? The first on checks is the page is a category archive -which is not- while the later checks if post has the category you are passing to the function.

    Please try that out and let me know,
    Best,
    Nico

    #1003430
    Courtney
    Participant

    Hi!

    I also am trying to do something that is only available if you’re on a category page — so I wanted to do an is_category() call and then do something. However, it’s not working. Any ideas why?

    #1003434
    Courtney
    Participant

    This reply is private.

    #1003520
    Nico
    Member

    Hey Coutney,

    Thanks for opening a new thread 🙂

    Maybe I get to help you out there,
    Best,
    Nico

    #1007383
    jmegordon
    Participant

    Hi Nico,

    Still no luck unfortunately –

    <?php
    if (has_category(‘1284’))
    {
    echo ‘This is a 1* rated tournament’;
    }
    elseif (has_category(‘1285’))
    {
    echo ‘This is a 2* rated tournament’;
    }
    else
    {
    echo ”;
    }
    ?>

    Any ideas?

    Many thanks,

    #1007414
    jmegordon
    Participant

    Hi Nico,

    Managed to find the solution – I needed to add ‘tribe_events_cat’. I’ve pasted the working version below for future reference

    <?php
    if( has_term( ‘1284’, ‘tribe_events_cat’ ) ) {
    echo ‘This is a 1* rated tournament’;
    }
    elseif( has_term( ‘1283’, ‘tribe_events_cat’ ) ) {
    echo ‘This is a 2* rated tournament’;
    }
    ?>

    Many thanks

    #1007422
    Nico
    Member

    Hey Gerry,

    Thanks for following up! Reviewing our previous conversation I realize that has_category won’t work as it will only check for default post categories and not custom taxonomies. Sorry, my bad 🙁

    Just tried this code inside the loop in single-events.php template and it’s working on my end:

    <?php if ( has_term('cat-slug','tribe_events_cat') ) : ?>
    <?php //if ( has_term(152,'tribe_events_cat') ) : ?>
    This is a cat
    <?php else: ?>
    This is not a cat
    <?php endif; ?>

    Note that has_term accepts taxonomy slug (string, goes between quotes) or taxonomy ID (int, goes without quotes).

    Please let me know if you can make it work this time,
    Best,
    Nico

    #1012270
    Support Droid
    Keymaster

    This topic has not been active for quite some time and will now be closed.

    If you still need assistance please simply open a new topic (linking to this one if necessary)
    and one of the team will be only too happy to help.

Viewing 9 posts - 1 through 9 (of 9 total)
  • The topic ‘Display default text depending on category’ is closed to new replies.