• I’ve aksed this in other sections of the forums without any luck.

    I’m trying to do a php if statement on my tag archives

    in my wordpress header, something like this:

    <?php if (is_tag() && !is_tag(array('1','2','3')) && $count > 3) { ?> <html goes here> <?php } ?>

    So first i need to check if the post is a tag, if it is a tag i need it to check it’s not one of the follow tags 1,2 or 3. Then i need to check that the tag has less posts than 3 to trigger the html output

    Any php / wordpress genius able to assist me in accomplishing something like this?

    Thank you!

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator bcworkz

    (@bcworkz)

    This should work:

    <?php global $wp_query;
    if ($wp_query->is_main_query() && $wp_query->is_tag(array(1,2,3,) && 3 > $wp_query->post_count)) { ?>
       <html goes here>
    <?php } ?>

    Thread Starter Rado

    (@jeriksson)

    Thanks for the reply but that doesn’t work.

    The html output renders on all tag pages when i use your code.

    The tags in the array should be skipped and tags which have more than 3 posts should also be skipped from outputting the html, any ideas?

    Thanks again.

    Moderator bcworkz

    (@bcworkz)

    Err, I apparently got the logic backwards! My bad. Try this:

    <?php global $wp_query;
    if ($wp_query->is_main_query() && (!$wp_query->is_tag(array(1,2,3,)) || 3 > $wp_query->post_count)) { ?>
       <html goes here>
    <?php } ?>

    It’s a little unclear if your actual logical intent for the tag IDs and post count should be AND or OR. I chose OR by using ‘||’. If that turns out to be incorrect, change the ‘||’ to ‘&&’ (no quotes)

    Thread Starter Rado

    (@jeriksson)

    Seems to be working great, thanks a lot for this!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Do something to a tag archive if post_count less than 3, how?’ is closed to new replies.