Forums

[resolved] "if category x"-conditions on posts @ index.php ? (5 posts)

  1. buntstift
    Member
    Posted 3 years ago #

    hello,

    i noticed that the conditional-tags i used inside "archive.php" won't work at "index.php". actually this is logical, because
    "is_category(x)" will never be true at index.php, since it is the main page, not belonging to any category, right ?

    but is it possible to place conditional tags onto "index.php" changing the representation of posts belonging to one specified category ?
    like having all posts displayed as an excerpt except one specific category being displayed via "the_content" at the front page?

    this is the code which works at archive.php, but of course doesn't work at index.php:

    <?php if ( is_category(4)) { ?>
    <?php the_content(); ?>
    <?php } else { ?>
    <?php the_excerpt(); ?>
    <?php } ?>

    is it possible to get what i obviously tried with this piece of code at index.php ?

    i already tried the "in_category"-tag, simply via replacing the "is" with "in" but this returned as a blank page.

    i would be thankful for any comment. i am still a php noob.

  2. MichaelH
    Volunteer
    Posted 3 years ago #

    The conditional tag, in_category, is the way to proceed and is depicted in the Codex article, The Loop.

    Make sure you are using the correct Category ID!

  3. andymacdonalduk
    Member
    Posted 2 years ago #

    Did you manage to resolve this, because i REALLY want to use this on my page right now.

  4. MichaelH
    Volunteer
    Posted 2 years ago #

    Are you saying you tried 'in_category' on a page template and it didn't work?

    If necessary, please paste all the code from the page template into a pastebin, such as http://wordpress.pastebin.ca and report the link back here so someone might find your problem. Thanks.

  5. andymacdonalduk
    Member
    Posted 2 years ago #

    Hey Michael,

    I didnt actually try the above code on my website before i actually posted here, but i have just used the above and it seems to work perfectly on my website, so thats my issue resolved.

    Thank you very much for replying though sir, it is very much appreciated.

    Andrew

Topic Closed

This topic has been closed to new replies.

About this Topic