Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

is_page() not working properly

Posted on 2012-12-20
5
Medium Priority
?
1,308 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 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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

How to create your own WordPress Theme Before I begin with the theme design tutorial, I would like to give you the basics of what is required to make a WordPress Theme. The most basic WordPress theme only requires 2 files: a style.css file and an…
While Plesk offers many potential benefits to website administrators, including compatibility with Windows Server and other leading technologies, the company has also been working to differentiate it from other control panels for content management…
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 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. …
Suggested Courses

824 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