• I want this conditional to work on all single posts EXCEPT if it is in category 8… but it doesn’t seem to work?
    if ( is_single()||!in_category('8')) {

    This is my full code

    <?php
    if ( is_single()||!in_category('8')) {
      $categories = get_the_category();
      if ($categories) {
        foreach ($categories as $category) {
          // echo "<pre>"; print_r($category); echo "</pre>";
          $cat = $category->cat_ID;
          $args=array(
            'cat' => $cat,
            'post__not_in' => array($post->ID),
            'posts_per_page'=>99,
            'caller_get_posts'=>1
          );
          $my_query = null;
          $my_query = new WP_Query($args);
          if( $my_query->have_posts() ) {
            echo '<h2>The '. $category->category_description . ' label</h2>';
            echo '<p>These are more clothes from the same '. $category->category_description . ' label</p>';
            while ($my_query->have_posts()) : $my_query->the_post(); ?>
              		<?php get_the_image( array( 'default_size' => 'medium', 'width'=>'130', 'height'=>'130', 'image_scan' => true, 'link_to_post' => true, 'link_to_image' => false, 'image_class' => 'alignleft', 'default_image' => 'https://spinifexcoolwear.com.au/wp-content/uploads/coolwear-260x277.jpg') ); ?>
             <?php
            endwhile;
          } //if ($my_query)
        } //foreach ($categories
      } //if ($categories)
      wp_reset_query();  // Restore global post data stomped by the_post().
    } //if (is_single())
    ?>

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi,

    It seems for what you’re trying to do; “single posts EXCEPT if it is in category 8“, your current code
    if ( is_single()||!in_category('8')) {
    Is actually saying if single OR not in cat 8, where you want to say, if single AND not in cat 8…

    Maybe try:

    if ( is_single() && !in_category('8')) {

    Try using AND instead of OR in this case because you want a condition where the page is single, AND the page is not in cat 8… if you use OR, it’ll be true as long as it’s a single page… if you use AND, it’ll only be “true” if both conditions (is single and not in cat 8), is true.

    Hope this helps.

    Q

    Thread Starter Pete

    (@perthmetro)

    Thanks for that, i’ll give it a whirl

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Conditional: is_single EXCEPT in_category 8’ is closed to new replies.