Support » Plugins and Hacks » Responsive Slider » [Feature request] Move the html output into a separate template

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Griden

    (@griden)


    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.

    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;
    			break;
    		endif;
    	endforeach;
    
    	// get the html code from the template
    	$html = "";
    	if ($template) :
    		ob_start();
    		include $template;
    		$html = ob_get_clean();
    	else :
    		new WP_Error('broke', __("No valid template file found for 'Responsive slider'"));
    	endif;
    
    	wp_reset_query();
    	return $html;
    }

    file: responsive-slider-template.php
    =======================

    <?php
    /*
     * Template file for "Responsive slider"
     */
    ?>
    
    <div class="responsive-slider flexslider">
    	<ul class="slides">
    		<?php
    		/*
    		 * Start the slides loop
    		 */
    		while ( $slides->have_posts() ) :
    			$slides->the_post();
    			global $post; ?>
    			<li>
    				<div id="slide-<?php the_ID(); ?>" class="slide">
    				<?php
    				/*
    				 * 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' ) ); ?>
    					</a>
    					<?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(); ?>
    					</a>
    				</h2>
    			</div><!-- #slide-x -->
    		</li>
    		<?php endwhile; // loop ends here ?>
    	</ul>
    </div><!-- #featured-content -->
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Feature request] Move the html output into a separate template’ is closed to new replies.