Forums

[resolved] the "if it's not tag" problem (9 posts)

  1. y4
    Member
    Posted 2 years ago #

    I've created an archive.php. The file is getting different designs for each category. I also want to make a design for tags page in blog.

    Please look at the following codes which is in archive.php:

    $category = get_the_category();
    $cat_id = $category[0]->cat_ID;
    
    if ( cat_id == 1 and !is_tag() ) {TEMPLATE FOR CATEGORY 1}
    if ( is_tag() ) {TAG PAGE TEMPLATE}

    I know the "!is_tag" doesn't work. But, what should i use instead of it? That's all problem. If i resolve this, i could be resolved all of the other "if not" problems as "is_day()", "is_month()" and "is_year()".

    I hope i could explain my problem. Thanks in advance.

  2. MichaelH
    Volunteer
    Posted 2 years ago #

    Wouldn't it be more like this?

    if ( $cat_id == 1 && !is_tag() ) {TEMPLATE FOR CATEGORY 1}

    Related:
    Stepping Into Template Tags
    Stepping Into Templates
    Template Hierarchy
    Conditional Tags

  3. y4
    Member
    Posted 2 years ago #

    yes, of course. i said the different designs used for each category.

  4. MichaelH
    Volunteer
    Posted 2 years ago #

    "yes, of course" meaning yes you agree with the code change I suggested?

  5. y4
    Member
    Posted 2 years ago #

    did you suggest something?

    if you did, you suggested what i already wrote.

    and you asked whether something would be more like that. i said "yes, of course" for that question.

    so, the problem is "!is_tag". it doesn't work. and, what must be instead of it? or, is it a code which works? i hope you know the solution of this problem.

  6. MichaelH
    Volunteer
    Posted 2 years ago #

    Works fine for me in the WordPress Default theme's wp-content/themes/default/archive.php when viewing a category archive.

    <?php
    if ( ! is_tag() ) {
      echo 'this is not a tag archive';
    }
    ?>

    Please note that I did suggest a line of code DIFFERENT than your line of code.

  7. y4
    Member
    Posted 2 years ago #

    it did NOT work, either.

    i applied my code with your code change. but it hasn't currently worked.

    it displays the results of both a "if" template, which is for a category, and the "if", which is for "is_tag".

    so, the problem is going on. and "! is_tag" doesn't work.
    where is the wrong?

  8. Mark / t31os
    Moderator
    Posted 2 years ago #

    Perhaps the problem is that you could be receiving query vars for both at once..

    In that case, your code just needs to account for that.. ie..

    if( is_tag() && is_category() ) {
    // whatever
    }
    elseif( is_tag() ) {
    // whatever
    }
    elseif( is_category() ) {
    // whatever
    }
    else {
    // It's neither, so do whatever
    }
  9. y4
    Member
    Posted 2 years ago #

    i just found the is_category function while searching. but thanks a lot to you though :)

    by the way, "is_category" must be in front of other conditions as the is_tag in your code.

Topic Closed

This topic has been closed to new replies.

About this Topic