'-1', 'orderby' => 'menu_order', 'order' => 'DESC', 'id' => 0, 'echo' => true, 'size' => 50, 'per_row' => 3, 'link_title' => true, 'title' => '', 'before' => '
', 'after' => '
', 'before_title' => '

', 'after_title' => '

', 'category' => 0 ); $args = wp_parse_args( $args, $defaults ); // Allow child themes/plugins to filter here. $args = apply_filters( 'woothemes_archives_timeline_args', $args ); $html = ''; do_action( 'woothemes_archives_timeline_before', $args ); // The Query. $query = $woothemes_archives->timeline->get_timeline_data( $args ); // The Display. if ( ! is_wp_error( $query ) && is_array( $query ) && count( $query ) > 0 ) { $dates_array = array(); $year_array = array(); $i = 0; $prev_post_ts = null; $prev_post_year = null; $distance_multiplier = 9; $html .= $args['before'] . "\n"; if ( '' != $args['title'] ) { $html .= $args['before_title'] . esc_html( $args['title'] ) . $args['after_title'] . "\n"; } $html .= '
' . "\n"; // Begin templating logic. $tpl = '%%DATE%% %%TITLE%% %%COMMENTS%%'; $tpl = apply_filters( 'woothemes_archives_timeline_item_template', $tpl, $args ); $i = 0; foreach ( $query as $post ) { setup_postdata( $post ); $post_ts = strtotime( $post->post_date ); $post_year = date( 'Y', $post_ts ); $template = $tpl; $i++; $image_size = apply_filters( 'woothemes_archives_timeline_image_size', 'thumbnail', $post ); $image = get_the_post_thumbnail( $post->ID, $image_size ); $date = get_the_date( 'F j', $post->post_date ) . '' . get_the_date( 'S', $post->post_date ) . ''; $comments = '' . _n( __( '1', 'woothemes-archives' ), sprintf( __( '%d', 'woothemes-archives' ), $post->comment_count ), $post->comment_count, 'woothemes-archives' ) . ''; $title = get_the_title(); if ( true == $args['link_title'] ) { $image = '' . $image . ''; $title = '' . $title . ''; } // Optionally display the image, if it is available. if ( has_post_thumbnail() ) { $template = str_replace( '%%IMAGE%%', $image, $template ); } else { $template = str_replace( '%%IMAGE%%', '', $template ); } $template = str_replace( '%%DATE%%', $date, $template ); $template = str_replace( '%%TITLE%%', $title, $template ); $template = str_replace( '%%COMMENTS%%', $comments, $template ); $template = apply_filters( 'woothemes_archives_timeline_template', $template, $post ); /* Handle the first year as a special case */ if ( is_null( $prev_post_year ) ) { $html .= '

' . $post_year . '

' . "\n"; $html .= '' . "\n"; $working_year = $prev_post_year; /* Print year headings until we reach the post year */ while ( $working_year > $post_year ) { $working_year--; $html .= '

' . $working_year . '

' . "\n"; } /* Open a new ordered list */ $html .= '' . "\n"; } $html .= '
' . "\n"; $html .= $args['after'] . "\n"; wp_reset_postdata(); } // Allow child themes/plugins to filter here. $html = apply_filters( 'woothemes_archives_timeline_html', $html, $query, $args ); if ( $args['echo'] != true ) { return $html; } // Should only run is "echo" is set to true. echo $html; do_action( 'woothemes_archives_timeline_after', $args ); // Only if "echo" is set to true. } // End woothemes_archives_timeline() } if ( ! function_exists( 'woothemes_archives_timeline_shortcode' ) ) { /** * The shortcode function for the "Timeline" view. * @since 1.0.0 * @param array $atts Shortcode attributes. * @param string $content If the shortcode is a wrapper, this is the content being wrapped. * @return string Output using the template tag. */ function woothemes_archives_timeline_shortcode ( $atts, $content = null ) { $args = (array)$atts; $defaults = array( 'limit' => '-1', 'orderby' => 'date', 'order' => 'DESC', 'echo' => true, 'size' => 50, 'link_title' => true, 'category' => 0 ); $args = shortcode_atts( $defaults, $atts ); // Make sure we return and don't echo. $args['echo'] = false; // Fix integers. if ( isset( $args['limit'] ) ) $args['limit'] = intval( $args['limit'] ); if ( isset( $args['size'] ) && ( 0 < intval( $args['size'] ) ) ) $args['size'] = intval( $args['size'] ); if ( isset( $args['category'] ) && is_numeric( $args['category'] ) ) $args['category'] = intval( $args['category'] ); // Fix booleans. foreach ( array( 'link_title' ) as $k => $v ) { if ( isset( $args[$v] ) && ( 'true' == $args[$v] ) ) { $args[$v] = true; } else { $args[$v] = false; } } return woothemes_archives_timeline( $args ); } // End woothemes_archives_timeline_shortcode() } add_shortcode( 'woothemes_archives_timeline', 'woothemes_archives_timeline_shortcode' ); ?>