Home › Forums › Calendar Products › Events Calendar PRO › Display default text depending on category
- This topic has 8 replies, 4 voices, and was last updated 10 years, 6 months ago by
Support Droid.
-
AuthorPosts
-
September 7, 2015 at 6:28 am #1002592
jmegordon
ParticipantHi,
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?
September 7, 2015 at 12:01 pm #1002706Nico
MemberHi 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,
NicoSeptember 9, 2015 at 12:41 pm #1003430Courtney
ParticipantHi!
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?
September 9, 2015 at 12:42 pm #1003434Courtney
ParticipantThis reply is private.
September 9, 2015 at 3:35 pm #1003520Nico
MemberHey Coutney,
Thanks for opening a new thread 🙂
Maybe I get to help you out there,
Best,
NicoSeptember 22, 2015 at 2:46 am #1007383jmegordon
ParticipantHi 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,
September 22, 2015 at 5:39 am #1007414jmegordon
ParticipantHi 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
September 22, 2015 at 6:05 am #1007422Nico
MemberHey 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,
NicoOctober 7, 2015 at 7:05 am #1012270Support Droid
KeymasterThis 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. -
AuthorPosts
- The topic ‘Display default text depending on category’ is closed to new replies.
