Solved

is_page() not working properly

Posted on 2012-12-20
5
1,076 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Did you use a default hosting installation of wordpress with the intention of it being your actual site?  Maybe you’ve installed it as a Blog to your current site and recently converted it to be the main site and do away with the old .htm pages.  An…
Like there are many different versions of Wordpress, there are also a handful of related side projects WordPress users should be familiar with.   All of these projects are open source and GPL licensed, which means there are few restrictions to us…
The purpose of this video is to demonstrate how to make a WordPress Site faster and smaller in size by cleaning up the database. This will be demonstrated using a Windows 8 PC. Plugin WP Optimize will be used. Go to your WordPress login page. T…
The purpose of this video is to demonstrate how to exclude a particular blog category from the main blog page. This is can be used when a category already has its own tab, or you simply want certain types of posts not to show up on the main blog. …

730 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