Jump to content

Recommended Posts

Hi, I'm using wordpress and woo commerce and i have a different banner slider on every product page and another on the main category page. I have tried using php to show the banner by id and by product title but it makes no difference, the error is still the same. On the main category page the main category banner shows along with the first product in that category, so two banners on the page. What am i doing wrong, surely by using an if statement that only works by ID, the banner should only work on this ID?

Here is the code:-

  <?php
  if(is_product_category( 'powders' ) ) {
      echo do_shortcode('[smartslider2 slider=14]');
      }
  ?>
 
  <?php
  if(get_the_ID()==78) {
     echo do_shortcode('[smartslider2 slider=11]');
     }
  ?>
     
 <?php
     if(get_the_ID()==82) {
         echo do_shortcode('[smartslider2 slider=12]');
         }
 ?>
 
 <?php
     if(get_the_ID()==85) {
         echo do_shortcode('[smartslider2 slider=13]');
         }
 ?>

I'll take a guess that both the statements are true when on that page.

It's both product category powders and one of those id's

 

You should probably use the conditional tags and can check for is_home(),is_page(),is_post(),is_single() and so on

http://codex.wordpress.org/Conditional_Tags

 

is_single()
    When a single post of any post type (except attachment and page post types) is being displayed.

 

is_singular()
    Returns true for any is_single(), is_page(), or is_attachment().

 

untested...

<?php
//check if singular
if(is_singular('post')){
//check for id's
    if(is_single('78')) {
        echo do_shortcode('[smartslider2 slider="11"]');
    }elseif(is_single('82')) {
        echo do_shortcode('[smartslider2 slider="12"]');
    }elseif(is_single('85')) {
        echo do_shortcode('[smartslider2 slider="13"]'); 
    }else{
        endif;
    }
}else{
//if not singular check for product categories
if(is_product_category('powders')) {
        echo do_shortcode('[smartslider2 slider="14"]');
    }
}
?>
Edited by QuickOldCar
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.