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( 'portfolio' );
- add_shortcode( 'portfolio', 'my_portfolio' );
- }
- function my_portfolio($attributes, $content = null) {
- $portfolio_categories_args = array(
- 'orderby' => 'name',
- 'order' => 'DESC',
- 'hide_empty' => true,
- 'exclude' => array(),
- 'exclude_tree' => array(),
- 'include' => array(),
- 'number' => '',
- 'fields' => 'all',
- 'slug' => '',
- 'parent' => '',
- 'hierarchical' => true,
- 'child_of' => 0,
- 'get' => '',
- 'name__like' => '',
- 'description__like' => '',
- 'pad_counts' => false,
- 'offset' => '',
- 'search' => '',
- 'cache_domain' => 'core'
- );
- $attributes = shortcode_atts(
- array(
- 'style' => false,
- 'align' => false,
- 'items_bg_color' => false,
- 'items_text_color' => false,
- 'pagination' => false,
- 'filters' => false,
- 'columns' => 3,
- 'category' => null,
- 'items' => null,
- 'ratio' => '3:2',
- 'indents' => false,
- 'meta' => false,
- ), $attributes);
- if ( ! in_array($attributes['columns'], array(2,3,4,5)))
- {
- $attributes['columns'] = 3;
- }
- if ( ! in_array($attributes['ratio'], array('3:2','4:3','1:1', '2:3', '3:4',)))
- {
- $attributes['ratio'] = '3:2';
- }
- if ( ! in_array($attributes['style'], array('type_1','type_2','type_3','type_4','type_5','type_6',)))
- {
- $attributes['style'] = 'type_1';
- }
- if ( ! in_array($attributes['align'], array('left','right','center',)))
- {
- $attributes['align'] = 'center';
- }
- $items_style = '';
- if ($attributes['items_bg_color'] != '') {
- $items_style .= 'background-color: '.$attributes['items_bg_color'].';';
- }
- if ($attributes['items_text_color'] != '') {
- $items_style .= ' color: '.$attributes['items_text_color'].';';
- }
- if ($items_style != '') {
- $items_style = ' style="'.$items_style.'"';
- }
- $attributes['ratio'] = str_replace(':', '-', $attributes['ratio']);
- global $wp_query;
- $attributes['items'] = intval($attributes['items']);
- $portfolio_items = (is_integer($attributes['items']) AND $attributes['items'] > 0)?$attributes['items']:$attributes['columns'];
- if ($attributes['pagination'] == 1 OR $attributes['pagination'] == 'yes') {
- if (is_front_page()) {
- $page_string = 'page';
- } else {
- $page_string = 'paged';
- }
- $paged = get_query_var($page_string) ? get_query_var($page_string) : 1;
- } else {
- $paged = 1;
- }
- $args = array(
- 'post_type' => 'us_portfolio',
- 'posts_per_page' => $portfolio_items,
- 'post_status' => 'publish',
- 'orderby' => 'date',
- 'order' => 'DESC',
- 'paged' => $paged
- );
- $filters_html = $sortable_class = '';
- $categories_slugs = null;
- if ( ! empty($attributes['category'])) {
- $categories_slugs = explode(',', $attributes['category']);
- $args['tax_query'] = array(
- array(
- 'taxonomy' => 'us_portfolio_category',
- 'field' => 'slug',
- 'terms' => $categories_slugs
- )
- );
- }
- if ($attributes['filters'] == 1 OR $attributes['filters'] == 'yes') {
- $categories = get_terms('us_portfolio_category', $portfolio_categories_args);
- if ( ! empty($categories_slugs))
- {
- foreach ($categories as $cat_id => $category)
- {
- if ( ! in_array($category->slug, $categories_slugs)) {
- unset($categories[$cat_id]);
- }
- }
- }
- if (count($categories) > 1) {
- $filters_html .= '<div class="w-filter">
- <div class="w-filter-list">
- ';
- foreach($categories as $category) {
- $filters_html .= '<div class="w-filter-item">
- <a class="w-filter-link" href="javascript:void(0);" data-filter=".'.$category->slug.'">'.$category->name.'</a>
- </div>';
- }
- $filters_html .= '<div class="w-filter-item active">
- <a class="w-filter-link" href="javascript:void(0);" data-filter="*">'.__('View all', 'us').'</a>
- </div>';
- $filters_html .= '</div>
- </div>';
- }
- }
- if ($filters_html != '') {
- $sortable_class = ' type_sortable';
- }
- $temp = $wp_query; $wp_query= null;
- $wp_query = new WP_Query($args);
- $portfolio_order_counter = 0;
- $indents_class = ($attributes['indents'] == 1 OR $attributes['indents'] == 'yes')?' with_indents':'';
- $output = '<div class="w-portfolio '.$attributes['style'].' align_'.$attributes['align'].' columns_'.$attributes['columns'].' ratio_'.$attributes['ratio'].$sortable_class.$indents_class.'">'.$filters_html.
- '<div class="w-portfolio-list">';
- while($wp_query->have_posts())
- {
- $wp_query->the_post();
- $post = get_post();
- $link = 'javascript:void(0);';
- $link_class = $link_target = '';
- $link_tag = 'div';
- if (rwmb_meta('us_custom_link') != '')
- {
- $link = rwmb_meta('us_custom_link');
- $link_class = ' external-link';
- if (rwmb_meta('us_custom_link_blank') == 1)
- {
- $link_target = ' target="_blank"';
- }
- $link_tag = 'a';
- }
- $additional_class = '';
- if (rwmb_meta('us_additional_class') != '') {
- $additional_class = ' '.rwmb_meta('us_additional_class');
- }
- if (has_post_thumbnail()) {
- $the_thumbnail = wp_get_attachment_image_src(get_post_thumbnail_id(), 'portfolio-list-'.$attributes['ratio']);
- $the_thumbnail = $the_thumbnail[0];
- $the_image = wp_get_attachment_image_src(get_post_thumbnail_id(), 'full');
- $the_image = '<img src="'.$the_image[0].'" alt="">';
- } else {
- $the_thumbnail = get_template_directory_uri() .'/img/placeholder/500x500.gif';
- $the_image = '<img src="'.get_template_directory_uri().'/img/placeholder/1200x800.gif" alt="">';
- }
- $item_categories_links = $item_categories_classes = '';
- $item_categories = get_the_terms(get_the_ID(), 'us_portfolio_category');
- if (is_array($item_categories))
- {
- $i = 0;
- foreach ($item_categories as $item_category)
- {
- $i++;
- $item_categories_links .= $item_category->name;
- if ($i < count($item_categories)) {
- $item_categories_links .= ' / ';
- $item_categories_classes .= ' '.$item_category->slug;
- }
- $item_categories_classes .= ' '.$item_category->slug;
- }
- }
- $meta_html = '';
- if ($attributes['meta'] == 'date') {
- $meta_html = get_the_date();
- } elseif ($attributes['meta'] == 'category') {
- $meta_html = $item_categories_links;
- }
- $output .= '<div class="w-portfolio-item'.$additional_class.$item_categories_classes.'">
- <div class="w-portfolio-item-h">
- <'.$link_tag.' class="w-portfolio-item-anchor'.$link_class.'" href="'.$link.'" data-id="'.$post->ID.'"'.$link_target.$items_style.'>
- <div class="w-portfolio-item-image"><img src="'.$the_thumbnail.'" alt=""></div>
- <div class="w-portfolio-item-meta">
- <div class="w-portfolio-item-meta-h">
- <h2 class="w-portfolio-item-title">'.get_the_title().'</h2>
- <span class="w-portfolio-item-text">'.$meta_html.'</span>
- </div>
- </div>
- </'.$link_tag.'>
- </div>
- </div>';
- }
- $output .= '</div>';
- if ($attributes['pagination'] == 1 OR $attributes['pagination'] == 'yes') {
- if ($pagination = us_pagination()) {
- $output .= '
- <div class="g-pagination align_center">
- '.$pagination.'
- </div>';
- }
- }
- $output .= '</div>';
- wp_reset_postdata();
- $wp_query= $temp;
- return $output;
- }
Advertisement
Add Comment
Please, Sign In to add comment