WordPress.org

Ready to get started?Download WordPress

Forums

Meteor Slides
[resolved] Slideshow Template Tag - Page Slug for Slideshow Slug (12 posts)

  1. inhouse
    Member
    Posted 2 years ago #

    I have many slideshows for a site I'm building (probably 40). I'd like to place a template tag in a page template that controls many pages. The trick is, I'd like to have the code place the slideshow that corresponds to the specific page you're visiting. So if the page is called "about-us", display the slideshow "about-us". I have matched the slideshow slugs to the page slugs. Is this possible or is there a different way of doing this? I really don't want to place a shortcode on every single page. Not only is that method tedious but it's not break proof. Thanks in advance.

    I know this is incorrect, but just as an example.
    <?php if ( function_exists( 'meteor_slideshow' ) ) { meteor_slideshow( "the_ID()", "width: '650'" ); } ?>

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

  2. Josh Leuze
    Member
    Plugin Author

    Posted 2 years ago #

    Sure, you can do that. Try using this code:

    <?php if ( function_exists( 'meteor_slideshow' ) ) {
    	global $post;
    	$ms_page_slug = $post->post_name;
    	$ms_slideshow_check = term_exists( $ms_page_slug, 'slideshow' );
    	if ( !empty( $ms_slideshow_check ) ) {
    		meteor_slideshow( $ms_page_slug, "" );
    	} else {
    		meteor_slideshow( "default", "" );
    	}
    } ?>

    That code will get the page slug, check if there is a slideshow with the same slug and if there is load that slideshow, otherwise, load a default slideshow.

  3. inhouse
    Member
    Posted 2 years ago #

    Josh, that worked perfectly. That's so much cleaner than using the shortcode on every page. I'm asking a lot here, but would it be possible that if there is no slideshow with the same title as the page slug, to defer to the parent slug? So display images that were on the parent page if no slideshows exist for the child page? Would this work even if you're on a 3rd or 4th level page? I wouldn't say it should continue up the tree, just look for the immediate parent. That is so useful, I can't thank you enough.

  4. Josh Leuze
    Member
    Plugin Author

    Posted 2 years ago #

    No problem, try this code:

    <?php if ( function_exists( 'meteor_slideshow' ) ) {
    	global $post;
    	$ms_page_slug       = $post->post_name;
    	$ms_parent_id       = get_post($post->post_parent);
    	$ms_parent_slug     = $ms_parent_id->post_name;
    	$ms_slideshow_check = term_exists( $ms_page_slug, 'slideshow' );
    	$ms_parent_check    = term_exists( $ms_parent_slug, 'slideshow' );
    	if ( !empty( $ms_slideshow_check ) ) {
    		meteor_slideshow( $ms_page_slug, "" );
    	} else if ( !empty( $ms_parent_check ) ) {
    		meteor_slideshow( $ms_parent_slug, "" );
    	} else {
    		meteor_slideshow( "default", "" );
    	}
    } ?>

    It also gets the parent page's slug and checks to see if that matches a slideshow, then it tries to load the page's slideshow, then the parent's slideshow, and then a default slideshow if there are no matches.

  5. inhouse
    Member
    Posted 2 years ago #

    Thanks so much Josh. I modified just a tiny bit to add size and to remove the default slideshow if no others are found but other than that, it's perfect!

    <?php if ( function_exists( 'meteor_slideshow' ) ) {
    	global $post;
    	$ms_page_slug       = $post->post_name;
    	$ms_parent_id       = get_post($post->post_parent);
    	$ms_parent_slug     = $ms_parent_id->post_name;
    	$ms_slideshow_check = term_exists( $ms_page_slug, 'slideshow' );
    	$ms_parent_check    = term_exists( $ms_parent_slug, 'slideshow' );
    	if ( !empty( $ms_slideshow_check ) ) {
    		meteor_slideshow( $ms_page_slug, "height: '250', width: '650'" );
    	} else if ( !empty( $ms_parent_check ) ) {
    		meteor_slideshow( $ms_parent_slug, "height: '250', width: '650'" );
    	} else {
    	}
    } ?>
  6. Josh Leuze
    Member
    Plugin Author

    Posted 2 years ago #

    Cool, glad that worked for you!

  7. WebWorld
    Member
    Posted 1 year ago #

    If I use the code you posted, where would I substitute slug name which is also page name? I have two slide shows for the header - one for services page (with slideshow slug "services", and the other for all the other pages (with slideshow slug "home". I couldn't get the code to work. Thanks. Site url with 1 slideshow showing in header is: http://utopiahomeservices.com/

    <?php if ( function_exists( 'meteor_slideshow' ) ) {
    global $post;
    $ms_page_slug = $post->post_name;
    $ms_parent_id = get_post($post->post_parent);
    $ms_parent_slug = $ms_parent_id->post_name;
    $ms_slideshow_check = term_exists( $ms_page_slug, 'slideshow' );
    $ms_parent_check = term_exists( $ms_parent_slug, 'slideshow' );
    if ( !empty( $ms_slideshow_check ) ) {
    meteor_slideshow( $ms_page_slug, "" );
    } else if ( !empty( $ms_parent_check ) ) {
    meteor_slideshow( $ms_parent_slug, "" );
    } else {
    meteor_slideshow( "default", "" );
    }
    } ?>

  8. Josh Leuze
    Member
    Plugin Author

    Posted 1 year ago #

    @WebWorld That code is automatic, it get the page slug and tried to match it to a slideshow slug and load the corresponding slideshow. So the only slideshow slug you have to enter is for the default slideshow.

    If the services page has the slug "services", and there is a slideshow with a matching slug, that should be loaded automatically on that page. Then if you want the slideshow with the "home" slug loaded as the default, just replace "default" in the code with "home".

  9. reptyler
    Member
    Posted 1 year ago #

    I am assuming this code goes in the functions.php. If not where?

  10. Josh Leuze
    Member
    Plugin Author

    Posted 1 year ago #

    No, it goes where ever you want the slideshow to be, just like the default version of the slideshow template tag.

  11. reptyler
    Member
    Posted 1 year ago #

    Sorry Josh, I'm lost. I'm using the Weaver Theme on this build out, but have no idea where to put this code. I am dealing with a live site and do not what to make changes without knowing they're correct. I do appreciate your patients.

  12. Josh Leuze
    Member
    Plugin Author

    Posted 1 year ago #

    So you're using the slideshow shortcode in the theme options of Weaver? That will only let you load one specific slideshow, you can't use this code with that as you can't put PHP in that spot.

    To do this you'd have to create a child theme of Weaver, copy the header.php file from Weaver into the child theme, and add this code to that file.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic