WordPress.org

Ready to get started?Download WordPress

Forums

Meteor Slides
[resolved] Insert PHP into is_home statement (8 posts)

  1. databell96
    Member
    Posted 1 year ago #

    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/

  2. Josh Leuze
    Member
    Plugin Author

    Posted 1 year ago #

    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();
    	}
    } ?>
  3. databell96
    Member
    Posted 1 year ago #

    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>
    } ?>
  4. Josh Leuze
    Member
    Plugin Author

    Posted 1 year ago #

    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>';
    	}
    } ?>
  5. databell96
    Member
    Posted 1 year ago #

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

  6. Josh Leuze
    Member
    Plugin Author

    Posted 1 year ago #

    You're welcome!

  7. russell@irondogmedia.com
    Member
    Posted 1 year ago #

    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?

  8. Josh Leuze
    Member
    Plugin Author

    Posted 1 year ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic