Hi,
I am porting a static site to WordPress and need to have 4 sliders. One is a default and the rest are page specific. But, for some reason, my code is not working:
<?php if ( function_exists( 'meteor_slideshow' ) ) {
if ( is_page( '34' ) ) {
meteor_slideshow( "tanning", "" );
} elseif ( is_page( '267' ) ) {
meteor_slideshow( "contact", "" );
} elseif ( is_page( '59' ) ) {
meteor_slideshow( "faq", "" );
} else {
meteor_slideshow( "main", "" );
}
} ?>
http://new.hollywoodtansnyc.com/
Dbranes answers:
Try to use <em>is_page( 34 ) </em>instead of <em>is_page( '34' )</em>, i.e.
<?php if ( function_exists( 'meteor_slideshow' ) ) {
if ( is_page(34) ) {
meteor_slideshow( "tanning", "" );
} elseif ( is_page(267) ) {
meteor_slideshow( "contact", "" );
} elseif ( is_page(59) ) {
meteor_slideshow( "faq", "" );
} else {
meteor_slideshow( "main", "" );
}
} ?>
or use page-slugs in <em>is_page('page_slug');</em>
Jagst3r21 comments:
Hi, unfortunately neither solutions worked. I am bafled.
Dbranes comments:
Does this work without any if/is_page:
meteor_slideshow( "tanning", "" );
You can also debug by placing this before your code:
echo " Current page has ID: ".$post->ID." and slug:".$post->post_name;
Jagst3r21 comments:
Yes, meteor_slideshow( "tanning", "" );
works without any if/is_page. Debugging only verified that I have the correct IDs and slugs, so I had everything right. Any other ideas what this could be? :(
Dbranes comments:
ok, maybe you could try this next
<?php
echo " Current page has ID: ".$post->ID." and slug:".$post->post_name;
if ( is_page(34) ) {
echo "We are on page with ID: 34";
meteor_slideshow( "tanning", "" );
} ?>
and visit page with id <em>34</em> to test;
Jagst3r21 comments:
Yes that test works, confirms that the page id is the same as the test.
Dbranes comments:
ok great, then we are making progress ;-)
next test would be:
<?php
echo " Current page has ID: ".$post->ID." and slug:".$post->post_name;
if ( is_page(34) ) {
echo "We are on page with ID: 34, let's view the slideshow 'tanning' ";
meteor_slideshow( "tanning", "" );
}elseif ( is_page(267) ) {
echo "We are on page with ID: 267, let's view the slideshow 'contact' ";
meteor_slideshow( "contact", "" );
}elseif ( is_page(59) ) {
echo "We are on page with ID: 59, let's view the slideshow 'faq' ";
meteor_slideshow( "faq", "" );
}else{
echo "We are on page with ID not in (34,59,267), let's view the slideshow 'main' ";
meteor_slideshow( "main", "" );
}
?>
Jagst3r21 comments:
Yes that works for all.
Dbranes comments:
so this is working as you want now?
Jagst3r21 comments:
For some reason it is not working. I have no idea why.
Jagst3r21 comments:
Ok, this can be marked as the dumbest issue ever. I did not have images set for the two that were not working -_-
Sorry I am dumb. I will award you the money for your time.
Gabriel Reguly answers:
Hi Jagst3r21,
Are you sure the code is not being used inside the loop?
<blockquote> Cannot Be Used Inside The Loop
Due to certain global variables being overwritten during The Loop is_page() will not work. In order to use it after The Loop you must call wp_reset_query() after The Loop. </blockquote>
http://codex.wordpress.org/Function_Reference/is_page
Regards,
Gabriel
Jagst3r21 comments:
It is just in my header.php file. I added the reset query and still no luck:
<?php if ( function_exists( 'meteor_slideshow' ) ) {
if ( is_page( '34' ) ) {
meteor_slideshow( "tanning", "" );
} elseif ( is_page( '267' ) ) {
meteor_slideshow( "contact", "" );
} elseif ( is_page( '59' ) ) {
meteor_slideshow( "faq", "" );
} else {
meteor_slideshow( "main", "" );
}
wp_reset_query();
} ?>
The only places it works are on the default main slider and the tanning page. The other two pages just show a white image.
Gabriel Reguly comments:
Dbranes just put you in the right direction, if/else is working, error is at meteor_slideshow function.
Arnav Joy answers:
try place at the top of the file
<?php wp_reset_query();?>
Jagst3r21 comments:
Hi, I added that before the opening <?php tag in my header.php and still no luck. Does someone want access to this ftp to try and solve this. I will ad an extra 10 dollars if you can help since I am on a deadline.
P.S. Idk why this is so hard, so maybe I am missing something obvious?