Home › Forums › Calendar Products › Events Calendar PRO › Category Conditional Stament
- This topic has 17 replies, 3 voices, and was last updated 8 years, 4 months ago by
Tony.
-
AuthorPosts
-
November 9, 2017 at 9:46 am #1379196
Tony
ParticipantOk so here is the issue –
I’m pulling in all event categories in an event loop displaying the next 6
<?php
$events = tribe_get_events( array(
'posts_per_page' => 6,
'start_date' => date( 'F j, Y' ),
)); ?>
And then in front of the three categories I have I need to display a certain corresponding icon such as this –
<?php if(is_tax(22)) { ?>educational
<?php } elseif (is_tax(23)) { ?>
program
<?php } elseif (is_tax(24)) { ?>
resource
<?php } else { ?>
FART
<?php } ?>
I have tried – is_tax() from this support forum –
I have tried – $cat_name = single_cat_title( ”, false ); from this support forum –
I have tried – has_term() from this support forum –
& this one –I understand that these Categories come through as Taxonomies (which makes no sense to me as to why this would be implemented this way?).
However nothing seems to work and it just keeps on FARTing.
Any help would be great.
Thanks
November 10, 2017 at 8:41 am #1380020Tony
ParticipantAnyone there? Trying to push this site live ASAP. Thanks.
November 10, 2017 at 4:21 pm #1380345Cliff
MemberHi, Tony.
Unless I’m mistaken, you’re not using is_tax() correctly. You should first pass the taxonomy name before the term ID.
$tecmain = Tribe__Events__Main::instance(); if ( is_tax( $tecmain::TAXONOMY, 22 ) ) { // do something for Event Category term #22 }Please let me know how this goes for you.
November 14, 2017 at 8:29 am #1382548Tony
ParticipantThis still does not work for me. Is this the implementation you would use here?
<?php $tecmain = Tribe__Events__Main::instance(); ?> <?php if(is_tax($tecmain::TAXONOMY, 22)) { ?> <p>C&P</p> <?php } elseif(is_tax($tecmain::TAXONOMY, 23)) { ?> <p>Fundraising</p> <?php } elseif(is_tax($tecmain::TAXONOMY, 24)) { ?> <p>Educational</p> <?php } else { ?> <img class="cat-icon" src="/wp-content/uploads/2017/11/Heart.png" /> <?php } ?>November 14, 2017 at 8:33 am #1382552Tony
ParticipantAnd just to be clear I tried the slug and nicename as well.
November 14, 2017 at 11:48 am #1382869Cliff
MemberWhere are you putting this code?
November 14, 2017 at 1:01 pm #1382935November 14, 2017 at 8:45 pm #1383212Cliff
MemberPlease provide me a link to download a .zip containing the full .php file and specify the location on my server to place it and I’ll see if I can figure it out.
November 15, 2017 at 10:24 am #1383711Tony
ParticipantThis reply is private.
November 16, 2017 at 9:03 am #1384763Tony
ParticipantCould it not be coming through because these events have two categories associated with them?
November 16, 2017 at 7:35 pm #1385237Cliff
MemberI see the file is called programs.php, which is not one of our template override files.
What is the full path to this file on your server so that I can better understand its context?
November 16, 2017 at 7:40 pm #1385242Cliff
MemberActually, I think I noticed that this file maybe loads for certain pages and then adds a sidebar displaying events.
If this is correct, is_tax() won’t work in this context. is_tax() works at URLs like http://wpshindig.com/events/category/wp-meetups/
You’re probably needing to use has_term() instead, although you’d have to figure out what works best for you and your custom coding.
November 17, 2017 at 8:44 am #1385715Tony
ParticipantTrue this is NOT a template override file. This is a custom template that I have made based of my page.php.
True this file only loads for pages using this as its template.
False, there is no sidebar, it just comes through as part of the content.
I have tried has_term(); and it still does not work.I simply started an events loop like this –
<?php $events = tribe_get_events( array( 'posts_per_page' => 6, 'start_date' => date( 'F j, Y' ), )); if ( empty( $events ) ) { echo 'Sorry, there are no upcoming events at this time.'; } else foreach( $events as $event ) { ?>And then I threw in a simple conditional using your recommendation like this.
<?php $tecmain = Tribe__Events__Main::instance(); ?> <?php if(is_tax($tecmain::TAXONOMY, 22)) { ?> <p>C&P</p> <?php } elseif(is_tax($tecmain::TAXONOMY, 23)) { ?> <p>Fundraising</p> <?php } elseif(is_tax($tecmain::TAXONOMY, 24)) { ?> <p>Educational</p> <?php } else { ?> <img class="cat-icon" src="/wp-content/uploads/2017/11/Heart.png" /> <?php } ?>This loop clearly works on my end because directly below this I display the title and event start time like this which comes through just fine –
<?php $title = get_the_title($event); ?> <?php if (strlen($title) > 30) { ?> <?php echo mb_strimwidth($title, 0, 30, '...'); ?> <?php } else { ?> <?php echo $title ?> <?php }?>Any ideas as to why this isn’t working?
November 17, 2017 at 3:23 pm #1386072Cliff
MemberMaybe try
has_term( 22, $tecmain::TAXONOMY, $event->ID )November 27, 2017 at 10:41 am #1392764Tony
ParticipantThis does not work. I get this error –
-
AuthorPosts
- The topic ‘Category Conditional Stament’ is closed to new replies.
