WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Code to find out if post belongs to X category (4 posts)

  1. imagyx
    Member
    Posted 1 year ago #

    Hi, I want to change a variable if the post belong to 'X' category in single.php.

    I'm using:

    <?php
    $post = $wp_query->post;
    if ( in_category('X') ) {
    $blog_single_page_style == 3;
    } else {
    }
    ?>

    But it's not working, any help would be appreciated, thanks!

  2. keesiemeijer
    moderator
    Posted 1 year ago #

    Have you tried adding the $post object to in_category():
    http://codex.wordpress.org/Function_Reference/in_category

    <?php
    // global $post object is available outside the loop on single.php
    if ( in_category('X', $post) ) {
    $blog_single_page_style == 3;
    } else {
    }
    ?>
  3. imagyx
    Member
    Posted 1 year ago #

    Brilliant! Thanks!

  4. keesiemeijer
    moderator
    Posted 1 year ago #

    You're welcome. I'm glad you've got it resolved :-)

Topic Closed

This topic has been closed to new replies.

About this Topic