Solved

is_page() not working properly

Posted on 2012-12-20
5
930 Views
Last Modified: 2012-12-26
Hi,

I have a wordpress site with WooCommerce and I am trying to display a banner on the main shop page.

I have added the following code to the wrapper-start.php (the shop loop's wrapper).

In the beginning is_page didn't work at all and didn't show the banner, and when I used is_archive it worked, but appeared on all pages with products on them and not just the main shop page. I found a post here that said to add wp_reset_query and use is_page. Now is_page is showing the banner but again, it shows up on all pages (like this one when I want it to show up only on the main /shop page.

Here is the code I have:

      
<?php wp_reset_query();
	if (!is_page('Shop')) {
	echo do_shortcode("[lbg_kenburnsslider settings_id='2']");
	}
	?>

Open in new window


Please advise.

Thanks
0
Comment
Question by:James-Wise
  • 3
  • 2
5 Comments
 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 38711950
I am trying to display a banner on the main shop page.

So that would imply you want the banner on shop and not elsewhere?

if (!is_page('Shop'))

Open in new window


Would put the banner everywhere not with a title of 'Shop'

If you meant to use the slug, it would have been:

if (!is_page('shop')) {
	echo do_shortcode("[lbg_kenburnsslider settings_id='2']");
	}

Open in new window


Given that a lot of people get confused by this, I always prefer to use the ID:
if (!is_page(20)) {
	echo do_shortcode("[lbg_kenburnsslider settings_id='2']");
	}

Open in new window


Finally, are you sure you want to be using ! here?
0
 

Author Comment

by:James-Wise
ID: 38714580
so i need to remove the ! before is_page, otherwise it is not?

That didn't work. (or is that not what you meant?)

Also does this page have an ID if it is a generated page, basically an archive page? if it does, how do I find what the ID is?

Thanks
0
 
LVL 70

Assisted Solution

by:Jason C. Levine
Jason C. Levine earned 500 total points
ID: 38714625
so i need to remove the ! before is_page, otherwise it is not?

Yes.  The ! in PHP is a not indicator.  

Also does this page have an ID if it is a generated page, basically an archive page?

Not really, but it's also not a page then.  WordPress pages are created through the Pages menu using a page template and only then will is_page() work as expected.  If this is an archive, then is_archive() is the correct test.

http://codex.wordpress.org/Function_Reference/is_archive
0
 

Accepted Solution

by:
James-Wise earned 0 total points
ID: 38714891
Well it seems is_archive() doesn't take parameters so all those pages return true.

But after digging in woocommerce codex I found that they have created an is_shop for the main shop page. that worked.
0
 

Author Closing Comment

by:James-Wise
ID: 38720950
Thanks again for the help! I learned a good bunch.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

I want to start by talking about the use of plug-ins for WordPress. I started a web-site for a company I was working for a few years ago; I had extremely basic knowledge of HTML. I am a Graphic Designer by trade so I invited the opportunity as a cha…
WordPress is constantly evolving, and with each evolution appears to get better and better.  One of the big drawbacks prior to version 3 was that there was no way to be able to set up a custom menu from the backend. The Old Way Adding menus is…
The purpose of this video is to demonstrate how to properly insert a Vimeo Video into a WordPress site or Blog. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp…
The purpose of this video is to demonstrate how to add AdSense Ads to a WordPress Website, and how to set up WordPress to automatically place Ads in Sidebars. This will be demonstrated using a Windows 8 PC. Log into your AdSense account. : Cli…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now