WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] is_page || in_page (10 posts)

  1. johnfotios
    Member
    Posted 2 years ago #

    If I say for eg.

    <?php (is_category(8)); ?>

    It does what I want it to do for that fine.

    If I say

    <?php (in_category(8)); ?>

    It does what I want it to do for that fine.

    But, as I want to test for either

    <?php (in_category(8) || (is_category(8));

    Neither of the things I want to happen work.

    Is there a problem putting in_category and is_category together? I'm full on rage.

  2. esmi
    Forum Moderator
    Posted 2 years ago #

    Not that I'm are of - although in_category() has to be used inside a Loop.

  3. alchymyth
    The Sweeper & Moderator
    Posted 2 years ago #

    Neither of the things I want to happen work.

    can you describe those things?

  4. johnfotios
    Member
    Posted 2 years ago #

    It's just different stylesheet links.

    I think it's the in_category that's the problem, as it isn't inside a loop. Are there any other ways to test which category the post is in?

  5. alchymyth
    The Sweeper & Moderator
    Posted 2 years ago #

    try to use in_category() together with AND is_single()

    example:
    <?php ( ( is_single() && in_category(8) ) || is_category(8) );

  6. Chip Bennett
    Theme Review Admin
    Posted 2 years ago #

    The is_category() conditional tests to see if the current page is a category archive index page. The in_category() conditional tests to see if the current post has the specified category.

    If in_category() is used outside the Loop, then you need to pass the $post object to it.

    It's just different stylesheet links.

    Can you describe - in human rather than code terms - what exactly you're trying to accomplish/implement?

    What exactly are you trying to do, and where exactly are you putting your code to implement what you're trying to do?

  7. johnfotios
    Member
    Posted 2 years ago #

    Right, the codes a huge mess. I'm trying to patch up something that was made a couple of years ago.

    In human terms (if it's possible :P), I just want to use a different stylesheet depending on which category a post is in (so it has a different header image + font styles etc). But I'm running the in_category from header.php

    Pretty much:

    <?php if ( in_category(10) || is_category(10) ): ?>
    <a rel="stylesheet" type="text/css" href="styles-1.css">
    <?php elseif ( in_category(8) || is_category(8) ): ?>
    <a rel="stylesheet" type="text/css" href="styles-2.css">
    <?php else: ?>
    <a rel="stylesheet" type="text/css" href="styles-3.css">
    <?php endif; ?>
    </head>
  8. johnfotios
    Member
    Posted 2 years ago #

    And it seems to use style-1.css for both category 10 & 8, and then style-3.css for any other categories. Piece of #£%&!

  9. Chip Bennett
    Theme Review Admin
    Posted 2 years ago #

    Try this instead:

    if ( is_category( 10 ) || ( is_single() && in_category( 10 ) ) {}

    ...which is, of course, exactly what @Alchymyth suggested :)

    Another thing: where exactly do these stylesheets reside? Are they in the document root, or in the Theme directory? If they're in the Theme's directory, you'll need to change this:

    href="styles-1.css"

    ...to this:

    href="<?php get_template_directory_uri(); ?>/styles-1.css"
  10. Chip Bennett
    Theme Review Admin
    Posted 2 years ago #

    And it seems to use style-1.css for both category 10 & 8, and then style-3.css for any other categories. Piece of #£%&!

    Do any posts have both category 8 AND category 10?

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.