Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End Conditional statement on category.php

  • This topic is empty.
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #235785
    amidigital
    Participant

    I would like to show something only if on specific category or subcategory page.

    Example, PGA is cat ID 2:
    http://www.mysite.com/category/PGA/
    http://www.mysite.com/category/PGA/swingers

    These attempts don’t work…

    <?php global $post;
    if ($post->post_parent == 2) {
    echo “test”;
    } ?>

    <?php if (in_category(‘CFB’)) : ?>
    test
    <?php endif; ?>

    #235792
    Alen
    Participant

    if ( get_query_var('CAT-SLUG') ) { // do stuff here }
    #235819
    amidigital
    Participant

    Not working :(

    <?php if ( get_query_var('pga') ) {
      echo "test"; 
    } 
    ?>  
    
    #235820
    Alen
    Participant

    @amidigital

    Sorry was on my mobile when I replied to this last time. This is the correct code, if you’re on category.php template.


    $category = single_cat_title('', false); if ( $category == 'test' ) { echo 'on test category'; }
    #235834
    amidigital
    Participant

    That works, but I would like the child category to apply as well.
    Tried a number of things like this, doesn’t work…

    <?php $category = single_cat_title('', false);
              $parentcategory = get_category_parents('', false);
    
    if ( $category == 'pga' || $parentcategory == 'pga') {
      echo 'pga cat';
    }
    ?>  
    
Viewing 5 posts - 1 through 5 (of 5 total)
  • The forum ‘Back End’ is closed to new topics and replies.