WordPress.org

Ready to get started?Download WordPress

Forums

If is_category issues (6 posts)

  1. ParadoxDev
    Member
    Posted 2 years ago #

    Hello,

    Basically I am making a website for a local shop using wordpress and woocommerce. They want a different background to be used on two of the categories, Which should be very straight forward...
    But, for some reason, it's deciding not to function as it should. I have tried using the woocommerce documentation, but quite frankly it's worthless (tells me nothing about how to use the parameters) so I attempted to use it just as the wordpress is_category. I have also tried using is_category.

    The problem is, it isn't registering any of my parameters. All it is doing is the basic is_category() function. I have tried using the name, slug and ID all without success.

    <?php if (is_product_category( 'legal-highs' )) : ?>
     <style type="text/css">
     	#wrapper {background-image:url(http://streetwiseheadshop.co.uk/wp-content/themes/streetwise2/images/background2.jpg) !important;}
    </style>
    <?php endif; ?>

    This is the code I'm using (obviously change is_product_category to is_category, it makes no difference so far...

    What am I doing wrong?

  2. Digital Raindrops
    Member
    Posted 2 years ago #

    Something like:

    <?php if (is_category() :
    	global $cat; //$cat = WordPress global holds the category->ID
    	if ($cat == 4 || $cat == 16 ) :
    	?>
    		<style type="text/css">
    			#wrapper {background-image:url(http://streetwiseheadshop.co.uk/wp-content/themes/streetwise2/images/background2.jpg) !important;}
    		</style>
    	<?php
    	endif;
    endif; ?>

    HTH

    David

  3. ParadoxDev
    Member
    Posted 2 years ago #

    Unfortunately that does absolutely nothing, no changes at all :/

  4. Digital Raindrops
    Member
    Posted 2 years ago #

    Where are you adding the code, and you did change the 4 and 16 to match your catergory->ID?

    The code could be in header.php inside the <head> </head> tags, or in a function in functions.php with an action to run it!

    Example:

    function my_background_style() {
    	if (is_category() {
    		global $cat; //$cat = WordPress global holds the category->ID
    		if ($cat == 4 || $cat == 16 ) { ?>
    			<style type="text/css">
    				#wrapper {background-image:url(http://streetwiseheadshop.co.uk/wp-content/themes/streetwise2/images/background2.jpg) !important;}
    			</style>
      <?php
    		}
    	}
    }
    add_action( 'wp_head', 'my_background_style' );

    HTH

    David

  5. ParadoxDev
    Member
    Posted 2 years ago #

    Sorry for the very late reply, this wasn't as high priority as other things so was left for a while.

    I have the code in my <head> tags, just under wp_head(),

    <?php if (is_category()) :
    	global $cat;
    	if ($cat == 42) :
    	?>
    		<style type="text/css">
    			#wrapper {background-image:url(http://streetwiseheadshop.co.uk/wp-content/themes/streetwise2/images/background2.jpg) !important;}
    		</style>
    	<?php
    	endif;
    endif; ?>
  6. sime0n
    Member
    Posted 1 year ago #

Topic Closed

This topic has been closed to new replies.

About this Topic