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) {
- $attributes = shortcode_atts(
- array(
- 'items' => null,
- 'category' => null,
- ), $attributes);
- if (is_numeric($attributes['items']) AND $attributes['items'] > 0)
- {
- $attributes['items'] = ceil($attributes['items']);
- } else
- {
- $attributes['items'] = -1;
- }
- $categories_slugs = '';
- if ( ! empty($attributes['category'])) {
- $categories_slugs = explode(',', $attributes['category']);
- $args['tax_query'] = array(
- array(
- 'taxonomy' => 'us_portfolio_category',
- 'field' => 'slug',
- 'terms' => $categories_slugs
- )
- );
- }
- $args = array(
- 'post_type' => 'us_portfolio',
- 'posts_per_page' => $attributes['items'],
- 'post__not_in' => get_option('sticky_posts')
- );
- if ( ! empty($attributes['category'])) {
- $args['tax_query'] = array(
- array(
- 'taxonomy' => 'us_portfolio_category',
- 'field' => 'slug',
- 'terms' => $categories_slugs
- )
- );
- }
- $portfolio = new WP_Query($args);
- $output = '<div class="w-portfolio">
- <div class="w-portfolio-h">
- <div class="w-portfolio-list">
- <div class="w-portfolio-list-h">';
- while($portfolio->have_posts())
- {
- $portfolio->the_post();
- $post = get_post();
- $category = wp_get_post_terms( $post->ID, 'us_portfolio_category');
- if (!empty($category)) {
- $category = '<h2 class="w-portfolio-item-title">' . $category[0]->name . '</h2>';
- }
- else {
- $category = '';
- }
- print_r($catefory);
- $link = 'javascript:void(0);';
- $link_class = $link_target = '';
- 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"';
- }
- }
- if (rwmb_meta('us_preview_fullwidth') == 1)
- {
- $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');
- $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="">';
- }
- remove_shortcode('subsection');
- add_shortcode('subsection', 'subsection_dummy');
- $content = get_the_content();
- $content = apply_filters('the_content', $content);
- $content = str_replace(']]>', ']]>', $content);
- remove_shortcode('subsection');
- add_shortcode('subsection', 'subsection');
- $output .= '<div class="w-portfolio-item'.$additional_class.'">
- <div class="w-portfolio-item-h">
- <a class="w-portfolio-item-anchor'.$link_class.'" href="'.$link.'" data-id="'.$post->ID.'"'.$link_target.'>
- <div class="w-portfolio-item-image" style="background-image:url('.$the_thumbnail.');"></div>
- <div class="w-portfolio-item-meta">
- <h2 class="w-portfolio-item-title">'.get_the_title().'</h2>
- '.$category.'
- </div>
- <div class="w-portfolio-item-hover"><i class="fa fa-plus"></i></div>
- </a>
- <div class="w-portfolio-item-details" style="display: none;">
- <div class="w-portfolio-item-details-h">
- <div class="w-portfolio-item-details-content"></div>
- <div class="w-portfolio-item-details-close"></div>
- <div class="w-portfolio-item-details-arrow to_prev"><i class="fa fa-angle-left"></i></div>
- <div class="w-portfolio-item-details-arrow to_next"><i class="fa fa-angle-right"></i></div>
- </div>
- </div>
- <textarea class="w-portfolio-hidden-content" style="display:none">'.$content.'</textarea>
- </div>
- </div>';
- }
- else
- {
- $extended_class = $additional_class = '';
- if (has_post_thumbnail()) {
- $the_thumbnail = wp_get_attachment_image_src(get_post_thumbnail_id(), 'portfolio-list');
- $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="">';
- }
- if (rwmb_meta('us_preview_image') != '')
- {
- $extended_class = ' type_extended';
- $preview_img_id = preg_replace('/[^\d]/', '', rwmb_meta('us_preview_image'));
- $preview_img = wp_get_attachment_image_src($preview_img_id, 'full');
- if ( $preview_img != NULL )
- {
- $the_image = '<img src="'.$preview_img[0].'" alt="">';
- }
- } elseif (rwmb_meta('us_preview_video') != '') {
- $extended_class = ' type_extended';
- $the_image = do_shortcode('[responsive_video link="'.rwmb_meta('us_preview_video').'"]');
- }
- if (rwmb_meta('us_additional_class') != '') {
- $additional_class = ' '.rwmb_meta('us_additional_class');
- }
- remove_shortcode('subsection');
- add_shortcode('subsection', 'subsection_dummy');
- $content = get_the_content();
- $content = apply_filters('the_content', $content);
- $content = str_replace(']]>', ']]>', $content);
- remove_shortcode('subsection');
- add_shortcode('subsection', 'subsection');
- $output .= '<div class="w-portfolio-item'.$extended_class.$additional_class.'">
- <div class="w-portfolio-item-h">
- <a class="w-portfolio-item-anchor'.$link_class.'" href="'.$link.'" data-id="'.$post->ID.'"'.$link_target.'>
- <div class="w-portfolio-item-image" style="background-image:url('.$the_thumbnail.');"></div>
- <div class="w-portfolio-item-meta">
- <h2 class="w-portfolio-item-title">'.get_the_title().'</h2>
- '.$category.'
- </div>
- <div class="w-portfolio-item-hover"><i class="fa fa-plus"></i></div>
- </a>
- <div class="w-portfolio-item-details" style="display: none;">
- <div class="w-portfolio-item-details-h">
- <div class="w-portfolio-item-details-content"></div>
- <div class="w-portfolio-item-details-close"></div>
- <div class="w-portfolio-item-details-arrow to_prev"><i class="fa fa-angle-left"></i></div>
- <div class="w-portfolio-item-details-arrow to_next"><i class="fa fa-angle-right"></i></div>
- </div>
- </div>
- <textarea class="w-portfolio-hidden-content" style="display:none">
- <div class="w-portfolio-item-details-content-preview">
- '.$the_image.'
- </div>
- <div class="w-portfolio-item-details-content-text">
- <h3>'.get_the_title().'</h3>
- '.$content.'
- </div>
- </textarea>
- </div>
- </div>';
- }
- }
- $output .= '</div>
- </div>
- </div>
- </div>';
- return $output;
- }
- function subsection ($attributes, $content)
- {
- $attributes = shortcode_atts(
- array(
- 'color' => '',
- 'full_width' => FALSE,
- 'full_height' => FALSE,
- 'background' => FALSE,
- 'parallax' => FALSE,
- 'video' => FALSE,
- 'video_mp4' => FALSE,
- 'video_ogg' => FALSE,
- 'video_webm' => FALSE,
- ), $attributes);
- $output_type = ($attributes['color'] != '')?' color_'.$attributes['color']:'';
- $full_width_type = ($attributes['full_width'] == 1)?' full_width':'';
- $full_height_type = ($attributes['full_height'] == 1)?' full_height':'';
- $background_style = '';
- if ($attributes['background'] != '')
- {
- if (is_numeric($attributes['background']))
- {
- $img_id = preg_replace('/[^\d]/', '', $attributes['background']);
- $img = wpb_getImageBySize(array( 'attach_id' => $img_id, 'thumb_size' => 'full' ));
- if ( $img != NULL )
- {
- $img = wp_get_attachment_image_src( $img_id, 'full');
- $img = $img[0];
- }
- $background_style = ' style="background-image: url('.$img.')"';
- }
- else
- {
- $background_style = ' style="background-image: url('.$attributes['background'].')"';
- }
- }
- $parallax_class = '';
- $parallax_data_output = '';
- if ($attributes['parallax']) {
- $parallax_class = ' with_parallax';
- // $parallax_data_output = ' data-prlx-xpos="50%" data-prlx-speed="'.$attributes['parallax_speed'].'"';
- }
- $video_html = $video_class = '';
- if ($attributes['video'] AND ($attributes['video_mp4'] != '' OR $attributes['video_ogg'] != '' OR $attributes['video_webm'] != '' )) {
- $video_class = ' with_video';
- $parallax_class = '';
- $video_mp4_part = ($attributes['video_mp4'] != '')?'<source type="video/mp4" src="'.$attributes['video_mp4'].'"></source>':'';
- $video_ogg_part = ($attributes['video_ogg'] != '')?'<source type="video/ogg" src="'.$attributes['video_ogg'].'"></source>':'';
- $video_webm_part = ($attributes['video_webm'] != '')?'<source type="video/webm" src="'.$attributes['video_webm'].'"></source>':'';
- $video_poster_part = ($attributes['background'] != '')?' poster="'.$attributes['background'].'"':'';
- $video_img_part = ($attributes['background'] != '')?'<img src="'.$attributes['background'].'" alt="">':'';
- $video_html = '<div class="video-background"><video loop="loop" autoplay="autoplay" preload="auto"'.$video_poster_part.'>'.$video_mp4_part.$video_ogg_part.$video_webm_part.$video_img_part.'</video></div>';
- }
- $output = '<div class="l-subsection'.$full_height_type.$full_width_type.$output_type.$parallax_class.$video_class.'"'.$background_style.$parallax_data_output.'>'.
- $video_html.
- '<div class="l-subsection-h">'.
- '<div class="l-subsection-hh g-html i-cf">'.
- do_shortcode($content).
- '</div>'.
- '</div>'.
- '</div>';
- return $output;
- }
- function subsection_dummy ($attributes, $content)
- {
- $attributes = shortcode_atts(
- array(
- 'type' => FALSE,
- 'with' => FALSE,
- ), $attributes);
- $output = do_shortcode($content);
- return $output;
- }
Advertisement
Add Comment
Please, Sign In to add comment