?
Solved

is_page() not working properly

Posted on 2012-12-20
5
Medium Priority
?
1,200 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 1500 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

Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

Question has a verified solution.

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

Do you think that WordPress is just for blogs?  Think again!  WordPress is really a fantastic all around platform that you can use to develop websites on.  Integrated into its basic functionality is the ability to create pages using your choice of a…
WordPress can be pretty daunting, especially for a beginner, so I thought it might be a good idea to write an article to show how easy it is to get started in WordPress and to design a custom theme.  The first step is to check with your hosting comp…
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 set up basic WordPress SEO. This will be demonstrated using a Windows 8 PC. The plugin used will be WordPress SEO by Yoast. Go to your WordPress login page. This will look like the following: myw…
Suggested Courses

800 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