Responsive Slider
[Feature request] Move the html output into a separate template (3 posts)

  1. frankobrillo
    Posted 2 years ago #

    It would be a great idea if you could move the html output into a separate template file. Html code is now hard coded into the plugin which makes it hard to customize. Besides that, any custom changes to the html would get lost when updating the plugin.

    Please let me know if you need some help with the coding.


  2. Griden
    Plugin Author

    Posted 2 years ago #

    I don't think template overwriting works for plugins the way it is for parent-child themes. Am I missing something?

    The best I can do is make the output filterable via a filter hook.

  3. frankobrillo
    Posted 2 years ago #

    It really doesn't have to be too complicated. My suggestion would be the following.

    1) Create a new file within the plugin directory and name it e.g. 'responsive-slider-template.php'
    2) Move the almost entire content from the function 'responsive_slider' (around line 230) to that file.
    3) If a file exists with the same name within the users theme directory, include that file, otherwise, include the default template.

    Nice and easy. See below for suggested code changes.

    Suggested code changes:

    file: responsive-slider.php


     * Output the slider.
     * @since 0.1
    function responsive_slider() {
    	$slides = new WP_Query( array( 'post_type' => 'slides', 'order' => 'ASC', 'orderby' => 'menu_order' ) );
    	$template = false;
    	$basename = "responsive-slider-template.php";
    	$basedir = array(
    		"theme" => get_template_directory(),
    		"plugin" => dirname(__FILE__),
    	foreach($basedir as $location => $path) :
    		if (file_exists($path."/".$basename)) :
    			$template = $path."/".$basename;
    	// get the html code from the template
    	$html = "";
    	if ($template) :
    		include $template;
    		$html = ob_get_clean();
    	else :
    		new WP_Error('broke', __("No valid template file found for 'Responsive slider'"));
    	return $html;

    file: responsive-slider-template.php

     * Template file for "Responsive slider"
    <div class="responsive-slider flexslider">
    	<ul class="slides">
    		 * Start the slides loop
    		while ( $slides->have_posts() ) :
    			global $post; ?>
    				<div id="slide-<?php the_ID(); ?>" class="slide">
    				 * output the post thumbnail
    				if ( has_post_thumbnail() ) :
    					// include the link
    					$has_link = get_post_meta( $post->ID, "_slide_link_url", true );
    					if ( $has_link ) : ?>
    					<a href="<?php echo get_post_meta( $post->ID, "_slide_link_url", true ); ?>" title="<?php the_title_attribute(); ?>">
    						<?php echo get_the_post_thumbnail( $post->ID, 'slide-thumbnail', array( 'class' => 'slide-thumbnail' ) ); ?>
    					<?php else : ?>
    						<?php echo get_the_post_thumbnail( $post->ID, 'slide-thumbnail', array( 'class' => 'slide-thumbnail' ) ); ?>
    					<?php endif; ?>
    				<?php endif; ?>
    				<h2 class="slide-title">
    					<a href="<?php echo get_post_meta( $post->ID, "_slide_link_url", true ); ?>" title="<?php the_title_attribute (); ?>">
    						<?php the_title(); ?>
    			</div><!-- #slide-x -->
    		<?php endwhile; // loop ends here ?>
    </div><!-- #featured-content -->

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Responsive Slider
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic


No tags yet.