Category Conditional Stament

Home Forums Calendar Products Events Calendar PRO Category Conditional Stament

Viewing 15 posts - 1 through 15 (of 17 total)
  • Author
    Posts
  • #1379196
    Tony
    Participant

    Ok 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 –

    Category conditional statement help needed

    I have tried – $cat_name = single_cat_title( ”, false ); from this support forum –

    Conditional based on Event Category

    I have tried – has_term() from this support forum –

    Conditional Categories


    & this one –

    Conditional tag for ANYTHING related to plugin?

    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

    #1380020
    Tony
    Participant

    Anyone there? Trying to push this site live ASAP. Thanks.

    #1380345
    Cliff
    Member

    Hi, 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.

    #1382548
    Tony
    Participant

    This 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 } ?>
    #1382552
    Tony
    Participant

    And just to be clear I tried the slug and nicename as well.

    #1382869
    Cliff
    Member

    Where are you putting this code?

    #1382935
    Tony
    Participant

    This reply is private.

    • This reply was modified 8 years, 5 months ago by Tony.
    #1383212
    Cliff
    Member

    Please 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.

    #1383711
    Tony
    Participant

    This reply is private.

    #1384763
    Tony
    Participant

    Could it not be coming through because these events have two categories associated with them?

    #1385237
    Cliff
    Member

    I 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?

    #1385242
    Cliff
    Member

    Actually, 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.

    #1385715
    Tony
    Participant

    True 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?

    #1386072
    Cliff
    Member

    Maybe try has_term( 22, $tecmain::TAXONOMY, $event->ID )

    #1392764
    Tony
    Participant

    This does not work. I get this error –

Viewing 15 posts - 1 through 15 (of 17 total)
  • The topic ‘Category Conditional Stament’ is closed to new replies.