WordPress.org

Ready to get started?Download WordPress

Forums

WordPress Posts Timeline
Multiple categories (3 posts)

  1. codde
    Member
    Posted 7 months ago #

    Is there a way to do multiple categories instead of just one?

    https://wordpress.org/plugins/wordpress-posts-timeline/

  2. loisjune
    Member
    Posted 2 months ago #

    Replace the code in the wordpress-posts-timeline.php in its plugin folder and you can use different category in your shortcode on different pages I also added attribute to change the thumbnail size.

    Sample:

    [wp-timeline cat="3" thumbsize="200"]

    function timeline_shortcode($atts){
    	extract( shortcode_atts( array(
    		      'cat' => '0',
    		      'type' => 'post',
    		      'show' => 5,
    		      'date' => 'Y',
    		      'length' => 10,
    		      'images' => 'no',
    		      'thumbsize' => '300',
         		), $atts ) );
    
         return display_timeline($args,$cat,$thumbsize); //assign variables here for category and thumbnail size
     }
    
    add_shortcode('wp-timeline', 'timeline_shortcode');
    
    //display the timeline
    function display_timeline($args,$cat,$thumbsize){
    
    	$post_args = array(
    			'post_type' => get_option('timeline_post_type'),
    			'numberposts' => get_option('timeline_show_posts'),
    			'category' => $cat, //get_option('timeline_post_category'),
    			'orderby' => 'post_date',
    			'order' => get_option('timeline_order_posts'),
    			'post_status' => 'publish',
    			'post_link' => get_option('timeline_post_link')
    		);
    
    		$posts = get_posts( $post_args );
    		$out .=  '<div id="timeline">';
    		$out .=   '<ul>';
    		foreach ( $posts as $post ) : setup_postdata($post);
    
    	        $out .=  '<li><div>';
    	        	if( get_option('timeline_post_link') == 'yes'){
    							$out .=  get_the_time(apply_filters( 'timeline_date_form', get_option('timeline_date_form') ), $post->ID);
    
    	        		$out .=  '<h3 class="timeline-date">';
    							if( get_option('timeline_show_titles') == 'yes'){
    								$out .=  " ".get_the_title($post->ID)." ";
    							}
    							$out .=  '</h3><br>';
    
    	        	} else {
    
    							$out .= get_the_time(apply_filters( 'timeline_date_form', get_option('timeline_date_form') ), $post->ID);
    							$out .=  '<h3 class="timeline-date">';
    							if( get_option('timeline_show_titles') == 'yes'){
    								$out .=  " ".get_the_title($post->ID)." ";
    							}
    							$out .=  '</h3><br>';
    	          }
    
    				if ( get_option('timeline_include_images') == 'yes' ){
    					if ( featured_image($thumbsize) == true && has_post_thumbnail( $post->ID ) ){
    						$out .=  '<a href="' . get_permalink($post->ID) . '" title="'.$post->title.'">';
    						$out .=  '<span class="timeline-image">' . get_the_post_thumbnail( $post->ID, 'timeline-thumb' ) . '</span>';
    						$out .=  '</a>';
    					}
    				}
    				$out .=  '<span class="timeline-text">'.timeline_text(get_option('timeline_text_length')).'</span>';
    				$out .=  '</div></li>';
    
        	endforeach;
    
    		$out .=  '</ul>';
    		$out .=  '</div> <!-- #timeline -->';
    		wp_reset_postdata();
    		return $out;
    }
    
    //trim text function found on http://www.jooria.com/Limit-Characters-From-Your-Text-a139.html
    function timeline_text($limit){
    	$str = get_the_content('', true, '');
    	$str = strip_tags($str);
        if(stripos($str," ") && $limit>=0){
        $ex_str = explode(" ",$str);
            if(count($ex_str)>$limit){
                for($i=0;$i<$limit;$i++){
    				$str_s.=$ex_str[$i]." ";
                }
    			$str_s.="";
    			return $str_s;
            }else{
    			return $str;
            }
        }else{
        return $str;
        }
    }
    
    //is shortcode active on page? if so, add styles to header
    function has_timeline_shortcode( $posts ) {
    
            if ( empty($posts) )
                return $posts;
    
            $shortcode_found = false;
    
            foreach ($posts as $post) {
    
                if ( !( stripos($post->post_content, '[wp-timeline') === false ) ) {
                    $shortcode_found = true;
                    break;
                }
            }
    
            if ( $shortcode_found ) {
                add_timeline_styles();
            }
            return $posts;
        }
    
    add_action('the_posts', 'has_timeline_shortcode');
    
    //add styles to header
    function add_timeline_styles(){
    	add_action('wp_print_styles', 'timeline_styles');
    }
    function timeline_styles(){
    
    		wp_register_style($handle = 'timeline', $src = plugins_url('css/timeline.css', __FILE__), $deps = array(), $ver = '1.0.0', $media = 'all');
    		wp_enqueue_style('timeline');
    }
    
    //check featured image theme support, add
    function featured_image($thumbsize){
    	if ( !current_theme_supports( 'post_thumbnails' ) ) {
    		if ( function_exists( 'add_theme_support' ) ) { 
    
    			add_theme_support( 'post-thumbnails' );
    			add_image_size( 'timeline-thumb', $thumbsize, 9999 ); //80 pixels wide (and unlimited height)
    			return true;
    		}
    	}
    	else{
    
    		add_image_size( 'timeline-thumb', $thumbsize, 9999 ); //80 pixels wide (and unlimited height)
    		return true;
    	}
    
    }
    
    //do shortcode for get_the_excerpt() && get_the_content()
    add_filter('get_the_content', 'do_shortcode');
    add_filter('get_the_excerpt', 'do_shortcode');
    
    //add options page
    require_once('inc/timeline_options.php');
  3. skss
    Member
    Posted 4 weeks ago #

    Thanks or the code, but if I used it, the link to the posts are gone.
    Under "Settings" I activate the option "Do you want to link to the post?" but i did not work with the new code.
    So what have I do wrong?

Reply

You must log in to post.

About this Plugin

About this Topic

Tags