mkwebworker
10/16/2013 - 8:31 AM

basic function for slideshow - actually not ready

basic function for slideshow - actually not ready

if( ! function_exists ( 'the_slideshow' )):
/*
 * the_slideshow() - get slides from cpt 'slide' and echo or return them 
   @param array $args - contains serval options
 */
	function the_slideshow( $args ) {
		 
	 ///// get arguments ///// 
	 
	 // default arguments
	 $defaults = array (
	 
		'items'			=> 	5, 			// number of displayed items
		'return'		=>	false, 		// echo return
		'before'	 	=> 	'<li>',		// before the img-tag
		'after'			=>	'</li>', 	// after the img-tag
		'wrap_before' 	=> 	false,		// wrapper before all items
		'wrap_after'	=>	false, 		// wrapper after all items
		'debug'			=>	false		// turns debug mode on or off
	 
	 );
	 
	 // Parse incoming $args into an array and merge it with $defaults
	 $args = wp_parse_args( $args, $defaults );
	 extract( $args, EXTR_SKIP );
	 
	 // validate $items
	 if( ! is_numeric( $items ) ) $items = $defaults['items']; // set to default
	

	
	///// init $debug /////
	if( $debug == true ) $debug_output = '<p>DEBUG MODE:</p>';


	 
	///// get slider content from cpt //////
	$query_args = array (
		
		'post_type'		=> 'slide', 			// the slideshow cpt-slug
		'posts_per_page'=> $items	// number of displayed items
		
	 );
	
	 $the_slides = get_posts( $query_args );
	 if( $debug == true ) $debug_output .= '<pre>'.print_r($the_slides, true).'</pre>';

	
	 ///// build html markup /////
	 $output = ''; // init
	 
	 if( count ( $the_slides < 0 ) ): 
	 
		foreach( $the_slides as $slide ):
		
			$output .= get_the_post_thumbnail( $slide->ID );
		
		endforeach;
	
	 
	 else:
	 
		$output .= __('No slides found');
	 
	 endif; // slides < 0
	 
	 
	
	
	 ///// debug mode - replace output /////
	 if( $debug == true) $output = $debug_output; 
	
	 ///// echo or return /////
	 if( $return == true ) return $output;
	 else echo $output;
	 

	
	
	}
 
endif; // function_exists