Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_action( 'after_setup_theme', 'child_theme_setup', 20 );
- function child_theme_setup() {
- remove_shortcode( 'blog' );
- add_shortcode( 'blog', 'my_blog' );
- }
- function my_blog($attributes, $content = null)
- {
- $attributes = shortcode_atts(
- array(
- 'pagination' => false,
- 'type' => 'square',
- 'show_date' => null,
- 'show_author' => null,
- 'show_categories' => null,
- 'show_tags' => null,
- 'show_comments' => null,
- 'show_read_more' => null,
- 'category' => null,
- 'items' => null,
- 'columns' => null,
- ), $attributes);
- $blog_thumbnails = array(
- 'square' => 'blog-list','rounded' => 'blog-list','masonry' => 'blog-grid'
- );
- if ( ! in_array($attributes['type'], array('square','rounded','masonry')))
- {
- $attributes['type'] = 'square';
- }
- if ( ! in_array($attributes['columns'], array(1,2,3)))
- {
- $attributes['columns'] = 1;
- }
- if ($attributes['pagination'] == 1 OR $attributes['pagination'] == 'yes') {
- $paged = get_query_var('paged') ? get_query_var('paged') : 1;
- } else {
- $paged = 1;
- }
- $args = array(
- // 'post_type' => 'us_portfolio',
- 'post_type' => 'post',
- 'post_status' => 'publish',
- 'orderby' => 'date',
- 'order' => 'DESC',
- 'paged' => $paged
- );
- $categories_slugs = null;
- if ( ! empty($attributes['category']))
- {
- $categories_slugs = explode(',', $attributes['category']);
- $args['tax_query'] = array(
- array(
- 'taxonomy' => 'category',
- 'field' => 'slug',
- 'terms' => $categories_slugs
- )
- );
- }
- $attributes['items'] = intval($attributes['items']);
- if (is_integer($attributes['items']) AND $attributes['items'] > 0) {
- $args['posts_per_page'] = $attributes['items'];
- }
- $classes = 'w-blog columns_'.$attributes['columns'];;
- switch ($attributes['type']) {
- case 'square': $classes .= ' imgpos_atleft';
- break;
- case 'rounded': $classes .= ' imgpos_atleft circle';
- break;
- case 'masonry': $classes .= ' imgpos_attop type_masonry';
- break;
- }
- $output = '<div class="'.$classes.'">
- <div class="w-blog-list">';
- global $wp_query;
- $temp = $wp_query; $wp_query= null;
- $wp_query = new WP_Query(); $wp_query->query($args);
- $us_thumbnail_size = $blog_thumbnails[$attributes['type']];
- if (empty($us_thumbnail_size))
- {
- $us_thumbnail_size = 'blog-list';
- }
- while ($wp_query->have_posts())
- {
- $wp_query->the_post();
- global $smof_data;
- $post_format = get_post_format()?get_post_format():'standard';
- global $post;
- $preview = (has_post_thumbnail())?get_the_post_thumbnail(get_the_ID(), $us_thumbnail_size):'';
- if (empty($preview) AND $us_thumbnail_size == 'blog-list')
- {
- $preview = '<img src="'.get_template_directory_uri().'/img/placeholder/500x500.gif" alt="">';
- }
- $output .= '<div class="' . join( ' ', get_post_class( 'w-blog-entry', null ) ) . '">
- <div class="w-blog-entry-h">
- <a class="w-blog-entry-link" href="'.get_permalink().'">';
- if ($preview) {
- $output .= '<span class="w-blog-entry-preview">'.$preview.'</span>';
- }
- // if ($post_format == 'quote')
- // {
- // $output .= '<div class="w-blog-entry-title">
- // <blockquote class="w-blog-entry-title-h">'.get_the_title().'</blockquote>
- // </div>';
- // }
- // else
- // {
- $output .= '<h2 class="w-blog-entry-title"><span>'.get_the_title().'</span></h2>';
- // }
- $output .= '</a>
- <div class="w-blog-entry-body">
- <div class="w-blog-meta">';
- if ($attributes['show_date'] == 1 OR $attributes['show_date'] == 'yes') {
- $output .= '<div class="w-blog-meta-date">
- <i class="fa fa-clock-o"></i>
- <span>'.get_the_date().'</span>
- </div>';
- }
- if ($attributes['show_author'] == 1 OR $attributes['show_author'] == 'yes') {
- $output .= '<div class="w-blog-meta-author">
- <i class="fa fa-user"></i>';
- if (get_the_author_meta('url')) {
- $output .= '<a href="'.esc_url( get_the_author_meta('url') ).'">'.get_the_author().'</a>';
- } else {
- $output .= '<span>'.get_the_author().'</span>';
- }
- $output .= '</div>';
- }
- if ($attributes['show_categories'] == 1 OR $attributes['show_categories'] == 'yes') {
- $output .= '<div class="w-blog-meta-category">
- <i class="fa fa-folder-open"></i>';
- $categories = get_the_category();
- $categories_output = '';
- $separator = ', ';
- if($categories){
- foreach($categories as $category) {
- $categories_output .= '<a href="'.get_category_link( $category->term_id ).'" title="' . esc_attr( sprintf( __( "View all posts in %s" ), $category->name ) ) . '">'.$category->cat_name.'</a>'.$separator;
- }
- }
- $output .= trim($categories_output, $separator).'
- </div>';
- }
- if ($attributes['show_tags'] == 1 OR $attributes['show_tags'] == 'yes') {
- $tags = wp_get_post_tags($post->ID);
- if ($tags) {
- $output .= '<div class="w-blog-meta-tags">
- <i class="fa fa-tags"></i>';
- $tags_output = '';
- $separator = ', ';
- foreach($tags as $tag) {
- $tags_output .= '<a href="'.get_tag_link($tag->term_id).'">'.$tag->name.'</a>'.$separator;
- }
- $output .= trim($tags_output, $separator).'
- </div>';
- }
- }
- if ($attributes['show_comments'] == 1 OR $attributes['show_comments'] == 'yes') {
- if ( ! (get_comments_number() == 0 AND ! comments_open() AND ! pings_open())) {
- $output .= '<div class="w-blog-meta-comments">';
- $output .= '<i class="fa fa-comments"></i>';
- $number = get_comments_number();
- if ( 0 == $number ) {
- $comments_link = get_permalink() . '#respond';
- }
- else {
- $comments_link = esc_url(get_comments_link());
- }
- $output .= '<a href="'.$comments_link.'">';
- if ( $number > 1 )
- $output .= str_replace('%', number_format_i18n($number), __('% Comments', 'us'));
- elseif ( $number == 0 )
- $output .= __('No Comments', 'us');
- else // must be one
- $output .= __('1 Comment', 'us');
- $output .= '</a></div>';
- }
- }
- $output .= '</div>';
- $output .= '<div class="w-blog-entry-short">';
- $excerpt = get_the_content(get_the_ID());
- $excerpt = do_shortcode($excerpt);
- $excerpt = apply_filters('the_excerpt', $excerpt);
- $excerpt = str_replace(']]>', ']]>', $excerpt);
- $excerpt_length = apply_filters('excerpt_length', 55);
- $excerpt_more = apply_filters('excerpt_more', ' ' . '[...]');
- $excerpt = wp_trim_words( $excerpt, $excerpt_length, $excerpt_more );
- $output .= $excerpt;
- $output .= '</div>';
- if ($attributes['show_read_more'] == 1 OR $attributes['show_read_more'] == 'yes') {
- $output .= '<a class="w-blog-entry-more g-btn color_faded outlined size_small" href="'.get_permalink().'"><span>'.__('Read More', 'us').'</span></a>';
- }
- $output .= '</div>
- </div>
- </div>';
- }
- $output .= '</div></div>';
- if ($attributes['pagination'] == 1 OR $attributes['pagination'] == 'yes') {
- if ($pagination = us_pagination()) {
- $output .= '<div class="w-portfolio-pagination">
- <div class="g-pagination align_center">
- '.$pagination.'
- </div>
- </div>';
- }
- }
- wp_reset_postdata();
- $wp_query= $temp;
- return $output;
- }
Advertisement
Add Comment
Please, Sign In to add comment