WordPress.org

Support

Support » Plugins and Hacks » [Resolved] [Plugin: Meteor Slides] Insert PHP into is_home statement

[Resolved] [Plugin: Meteor Slides] Insert PHP into is_home statement

  • I’m trying to figure out how to inject the PHP properly for my Meteor Slides plugin so it only appears on the homepage. Nowhere else. I know to use the is_home conditional tag. But I tried this approach and it came across as invalid:

    <?php if (is_home()) { if ( function_exists( 'meteor_slideshow' ) ) { meteor_slideshow(); } ?>

    What’s the proper PHP to use in this instance?

    http://wordpress.org/extend/plugins/meteor-slides/

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author Josh Leuze

    @jleuze

    You were missing a second closing curly brace, if you break it down to multiple lines and indent it like this you can see how it needs to be structured:

    <?php if ( is_home() ) {
    	if ( function_exists( 'meteor_slideshow' ) ) {
    		meteor_slideshow();
    	}
    } ?>

    That will load the slideshow in the blog homepage, which may or may not be your site’s homepage. If you are using the default WP settings and have the blog on the homepage that will work. If you have set a static page as your homepage you will need to use this instead:

    <?php if ( is_front_page() ) {
    	if ( function_exists( 'meteor_slideshow' ) ) {
    		meteor_slideshow();
    	}
    } ?>

    Cool. Thanks for the support and assistance. One other quick question. I wanted to make sure this function is in a div and the div can’t appear unless we’re on the homepage. So how would I include that?

    Like I know this wouldn’t work:

    <?php if ( is_home() ) {
    	<div class="slideshow">if ( function_exists( 'meteor_slideshow' ) ) {
    		meteor_slideshow();
    	}</div>
    } ?>
    Plugin Author Josh Leuze

    @jleuze

    Yes, that will work, but you can’t add the HTML right inside the PHP. You have to either write it as PHP using the echo function, or you have to close the PHP, add the HTML, and open it again. Here’s an all PHP example with the div added in:

    <?php if ( is_home() ) {
    	if ( function_exists( 'meteor_slideshow' ) ) {
    		echo '<div class="slideshow">';
    			meteor_slideshow();
    		echo '</div>';
    	}
    } ?>

    Thanks, JLeuze! That will help me in so many ways down the road!

    Plugin Author Josh Leuze

    @jleuze

    You’re welcome!

    I am running the slideshow on my front page (dev site, no live available yet) with this conditional section
    <?php if (is_front_page()) {
    echo ‘<div id=”featuredSlider”>’;
    echo ‘<div id=”slideContainer”>’;
    if ( function_exists( ‘meteor_slideshow’ ) ) { meteor_slideshow(); }
    echo ‘</div>’;
    echo ‘</div>’;
    }
    ?>
    So, I would expect the slideshow functionality to only be called if it is the front page.

    But when I go to any other page in my site, I get an error in the console saying “[cycle] terminating; zero elements found by selector” and it kills other jquery scripts that are supposed to be running on the page.

    I traced the error back to line 58 of the jquery.cycle.all.js file and read through the Is your DOM ready tutorial, but I can’t seem to see the need for this error since this file really shouldn’t even be loading if it’s not the front page.

    Am I missing something?

    Plugin Author Josh Leuze

    @jleuze

    That’s not an error, just a notice. jQuery Cycle is setup to not run if there are no slides, that notice won’t effect any other JavaScript. If there are any conflicts, you should see some errors.

    The slideshow is only loaded on whatever page or pages you add it to, but the scripts are loaded on all the pages. If you want to load the slideshow scripts on just the homepage, you can do it like this.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘[Resolved] [Plugin: Meteor Slides] Insert PHP into is_home statement’ is closed to new replies.