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
Solved

is_page() not working properly

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Woocommerce hooks for "Proceed To Checkout" and "Place Order" buttons ? 7 539
Server time zone 4 26
PHP AJAX JSON 2 77
I need help upgrading my urls 5 24
If you are looking for plug-ins to add functions to your WordPress small business web site, take some time to read though this comprehensive list.  These are all the plugins I use for my customers WordPress web sites, as well as my own.  Be sure to …
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…
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 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…

837 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