WordPress.org

Support

Support » How-To and Troubleshooting » [Resolved] is_page || in_page

[Resolved] is_page || in_page

  • 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.

Viewing 9 replies - 1 through 9 (of 9 total)
  • esmi

    @esmi

    Forum Moderator

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

    Michael

    @alchymyth

    Forum Moderator

    Neither of the things I want to happen work.

    can you describe those things?

    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?

    Michael

    @alchymyth

    Forum Moderator

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

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

    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?

    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>

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

    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"

    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?

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘[Resolved] is_page || in_page’ is closed to new replies.
Skip to toolbar