0

I am creating a wordpress theme from scratch. I have created a seperate page to show the Blog Posts. In my all pages I want to show a div class named as shopping-cart, but I want to hide it from page id=42 (wordpress-naked BlogPage) and single.php.

I have coded in my header.php like below

<?php if( is_page() ) { ?>

            <div  class="shopping-cart pull-right info" >Shopping Cart : <span class="simpleCart_quantity"></span> items - <span class="simpleCart_total"></span>
   <span class="ViewCART" onClick="myFunction()">View Cart</span>
 </div><!-----/.shopping-cart------------------------->

 <div class="down">
       <div class="triangle">&#x25B2;</div>

               <div ><h2>Your Cart Details</h2></div>
            <div class="cartData clearfix"><div class="left"><strong>Items: </strong><span class="simpleCart_quantity"></span></div>


                        <div class="right"><strong>Total: </strong><span class="simpleCart_total"></span></div></div>

            <div class="grandTotal"><strong>Grand Total:<div class="simpleCart_grandTotal"></div></strong></div>


           <div class="centercart"><a href="javascript:;" class="simpleCart_checkout" ><img src="<?php bloginfo('stylesheet_directory'); ?>/images/paypal.png"/></a></div>

            <div class="centercart"><a href="javascript:;" class="simpleCart_checkout" ><img src="<?php bloginfo('stylesheet_directory'); ?>/images/google-chk.png"/></a></div>
           <div class="centercart"><a href="javascript:;" class="simpleCart_empty"><img src="<?php bloginfo('stylesheet_directory'); ?>/images/clear.png"/></a></div>
             <div class="closecart"><span onClick="myFunction2()">Close</span></div>
            </div><!-----/.down------------->


<?php } ?>

It is working fine. The particular div shopping-cart is showing in the pages and hiding from the single.php. But the problem is that I have coded Blog as a separate blog.php which is a page named as wordpress-naked BlogPage and having it's page id =42. So now I want to hide the shopping-cart div in the wordpress-naked BlogPage and single.php together.

I got stuck in this. Can anyone please to sort it out. Thanks in advance.

2 Answers 2

1

Just change this:

<?php if( is_page() ) { ?>

to:

<?php if( is_page() && !is_page(42) ) { ?>

You can also try to use is_home() and is_front_page(). These 2 will be even better, since they are more universal (not based on pageId). If you change the page that is your home/front page, this will still work.

1
  • Thanks Drozdz. I was really stuck off in this. Thanks a lot again for your effort.. It worked... Commented Aug 3, 2013 at 9:14
0

$page = get_query_var('page_id');

if($page == 42 || is_single() ) {

$class= 'shopping-yourname';

} else {

$class = 'shopping-cart';

}

3
  • Well, I don't think you should do this like that. You should use is_page and is_single functions... Commented Aug 2, 2013 at 14:11
  • Yes, and that's why is_page function have parameter ;) Commented Aug 2, 2013 at 14:19
  • The other problem with your answer is that all it does, is setting some class variable. So it isn't an answer at all, I guess. Commented Aug 2, 2013 at 14:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.