ajayver

Untitled

Jul 14th, 2014
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 11.43 KB | None | 0 0
  1. add_action( 'after_setup_theme', 'child_theme_setup', 20 );
  2.  
  3. function child_theme_setup() {
  4.     remove_shortcode( 'portfolio' );
  5.     add_shortcode( 'portfolio', 'my_portfolio' );
  6. }
  7.  
  8. function my_portfolio($attributes, $content = null) {
  9.     $attributes = shortcode_atts(
  10.         array(
  11.             'items' => null,
  12.             'category' => null,
  13.         ), $attributes);
  14.  
  15.     if (is_numeric($attributes['items']) AND $attributes['items'] > 0)
  16.     {
  17.         $attributes['items'] = ceil($attributes['items']);
  18.     } else
  19.     {
  20.         $attributes['items'] = -1;
  21.     }
  22.  
  23.     $categories_slugs = '';
  24.  
  25.     if ( ! empty($attributes['category'])) {
  26.  
  27.         $categories_slugs = explode(',', $attributes['category']);
  28.         $args['tax_query'] = array(
  29.             array(
  30.                 'taxonomy' => 'us_portfolio_category',
  31.                 'field' => 'slug',
  32.                 'terms' => $categories_slugs
  33.             )
  34.         );
  35.     }
  36.  
  37.     $args = array(
  38.         'post_type' => 'us_portfolio',
  39.         'posts_per_page' => $attributes['items'],
  40.         'post__not_in' => get_option('sticky_posts')
  41.     );
  42.  
  43.     if ( ! empty($attributes['category'])) {
  44.         $args['tax_query'] = array(
  45.             array(
  46.                 'taxonomy' => 'us_portfolio_category',
  47.                 'field' => 'slug',
  48.                 'terms' => $categories_slugs
  49.             )
  50.         );
  51.     }
  52.  
  53.     $portfolio = new WP_Query($args);
  54.  
  55.     $output =   '<div class="w-portfolio">
  56.                     <div class="w-portfolio-h">
  57.                         <div class="w-portfolio-list">
  58.                             <div class="w-portfolio-list-h">';
  59.     while($portfolio->have_posts())
  60.     {
  61.         $portfolio->the_post();
  62.         $post = get_post();
  63.         $category = wp_get_post_terms( $post->ID, 'us_portfolio_category');
  64.         if (!empty($category)) {
  65.             $category = '<h2 class="w-portfolio-item-title">' . $category[0]->name . '</h2>';
  66.         }
  67.         else {
  68.             $category = '';
  69.         }
  70.        
  71.         print_r($catefory);
  72.  
  73.         $link = 'javascript:void(0);';
  74.         $link_class = $link_target = '';
  75.  
  76.         if (rwmb_meta('us_custom_link') != '')
  77.         {
  78.             $link = rwmb_meta('us_custom_link');
  79.             $link_class = ' external-link';
  80.             if (rwmb_meta('us_custom_link_blank') == 1)
  81.             {
  82.                 $link_target = ' target="_blank"';
  83.             }
  84.         }
  85.  
  86.         if (rwmb_meta('us_preview_fullwidth') == 1)
  87.         {
  88.  
  89.             $additional_class = '';
  90.             if (rwmb_meta('us_additional_class') != '') {
  91.                 $additional_class = ' '.rwmb_meta('us_additional_class');
  92.             }
  93.  
  94.             if (has_post_thumbnail()) {
  95.                 $the_thumbnail = wp_get_attachment_image_src(get_post_thumbnail_id(), 'portfolio-list');
  96.                 $the_thumbnail = $the_thumbnail[0];
  97.                 $the_image = wp_get_attachment_image_src(get_post_thumbnail_id(), 'full');
  98.                 $the_image = '<img src="'.$the_image[0].'" alt="">';
  99.             } else {
  100.                 $the_thumbnail =  get_template_directory_uri() .'/img/placeholder/500x500.gif';
  101.                 $the_image = '<img src="'.get_template_directory_uri().'/img/placeholder/1200x800.gif" alt="">';
  102.             }
  103.  
  104.             remove_shortcode('subsection');
  105.             add_shortcode('subsection', 'subsection_dummy');
  106.  
  107.             $content = get_the_content();
  108.             $content = apply_filters('the_content', $content);
  109.             $content = str_replace(']]>', ']]&gt;', $content);
  110.  
  111.             remove_shortcode('subsection');
  112.             add_shortcode('subsection', 'subsection');
  113.  
  114.             $output .=              '<div class="w-portfolio-item'.$additional_class.'">
  115.                                         <div class="w-portfolio-item-h">
  116.                                             <a class="w-portfolio-item-anchor'.$link_class.'" href="'.$link.'" data-id="'.$post->ID.'"'.$link_target.'>
  117.                                                 <div class="w-portfolio-item-image" style="background-image:url('.$the_thumbnail.');"></div>
  118.                                                 <div class="w-portfolio-item-meta">
  119.                                                     <h2 class="w-portfolio-item-title">'.get_the_title().'</h2>
  120.                                                     '.$category.'
  121.                                                 </div>
  122.                                                 <div class="w-portfolio-item-hover"><i class="fa fa-plus"></i></div>
  123.                                             </a>
  124.                                             <div class="w-portfolio-item-details" style="display: none;">
  125.                                                 <div class="w-portfolio-item-details-h">
  126.                                                     <div class="w-portfolio-item-details-content"></div>
  127.                                                     <div class="w-portfolio-item-details-close"></div>
  128.                                                     <div class="w-portfolio-item-details-arrow to_prev"><i class="fa fa-angle-left"></i></div>
  129.                                                     <div class="w-portfolio-item-details-arrow to_next"><i class="fa fa-angle-right"></i></div>
  130.                                                 </div>
  131.                                             </div>
  132.                                             <textarea class="w-portfolio-hidden-content" style="display:none">'.$content.'</textarea>
  133.                                         </div>
  134.                                     </div>';
  135.         }
  136.         else
  137.         {
  138.             $extended_class = $additional_class = '';
  139.             if (has_post_thumbnail()) {
  140.                 $the_thumbnail = wp_get_attachment_image_src(get_post_thumbnail_id(), 'portfolio-list');
  141.                 $the_thumbnail = $the_thumbnail[0];
  142.                 $the_image = wp_get_attachment_image_src(get_post_thumbnail_id(), 'full');
  143.                 $the_image = '<img src="'.$the_image[0].'" alt="">';
  144.             } else {
  145.                 $the_thumbnail =  get_template_directory_uri() .'/img/placeholder/500x500.gif';
  146.                 $the_image = '<img src="'.get_template_directory_uri().'/img/placeholder/1200x800.gif" alt="">';
  147.             }
  148.  
  149.             if (rwmb_meta('us_preview_image') != '')
  150.             {
  151.                 $extended_class = ' type_extended';
  152.                 $preview_img_id = preg_replace('/[^\d]/', '', rwmb_meta('us_preview_image'));
  153.                 $preview_img = wp_get_attachment_image_src($preview_img_id, 'full');
  154.  
  155.                 if ( $preview_img != NULL )
  156.                 {
  157.                     $the_image = '<img src="'.$preview_img[0].'" alt="">';
  158.                 }
  159.             } elseif (rwmb_meta('us_preview_video') != '') {
  160.                 $extended_class = ' type_extended';
  161.                 $the_image = do_shortcode('[responsive_video link="'.rwmb_meta('us_preview_video').'"]');
  162.             }
  163.  
  164.             if (rwmb_meta('us_additional_class') != '') {
  165.                 $additional_class = ' '.rwmb_meta('us_additional_class');
  166.             }
  167.  
  168.             remove_shortcode('subsection');
  169.             add_shortcode('subsection', 'subsection_dummy');
  170.  
  171.             $content = get_the_content();
  172.             $content = apply_filters('the_content', $content);
  173.             $content = str_replace(']]>', ']]&gt;', $content);
  174.  
  175.             remove_shortcode('subsection');
  176.             add_shortcode('subsection', 'subsection');
  177.  
  178.             $output .=              '<div class="w-portfolio-item'.$extended_class.$additional_class.'">
  179.                                         <div class="w-portfolio-item-h">
  180.                                             <a class="w-portfolio-item-anchor'.$link_class.'" href="'.$link.'" data-id="'.$post->ID.'"'.$link_target.'>
  181.                                                 <div class="w-portfolio-item-image" style="background-image:url('.$the_thumbnail.');"></div>
  182.                                                 <div class="w-portfolio-item-meta">
  183.                                                     <h2 class="w-portfolio-item-title">'.get_the_title().'</h2>
  184.                                                     '.$category.'
  185.                                                 </div>
  186.                                                 <div class="w-portfolio-item-hover"><i class="fa fa-plus"></i></div>
  187.                                             </a>
  188.                                             <div class="w-portfolio-item-details" style="display: none;">
  189.                                                 <div class="w-portfolio-item-details-h">
  190.                                                     <div class="w-portfolio-item-details-content"></div>
  191.  
  192.                                                     <div class="w-portfolio-item-details-close"></div>
  193.                                                     <div class="w-portfolio-item-details-arrow to_prev"><i class="fa fa-angle-left"></i></div>
  194.                                                     <div class="w-portfolio-item-details-arrow to_next"><i class="fa fa-angle-right"></i></div>
  195.  
  196.                                                 </div>
  197.                                             </div>
  198.                                             <textarea class="w-portfolio-hidden-content" style="display:none">
  199.                                                <div class="w-portfolio-item-details-content-preview">
  200.                                                    '.$the_image.'
  201.                                                </div>
  202.                                                <div class="w-portfolio-item-details-content-text">
  203.                                                    <h3>'.get_the_title().'</h3>
  204.                                                    '.$content.'
  205.                                                </div>
  206.                                            </textarea>
  207.                                         </div>
  208.                                     </div>';
  209.         }
  210.  
  211.  
  212.     }
  213.     $output .=              '</div>
  214.                         </div>
  215.                     </div>
  216.                 </div>';
  217.  
  218.     return $output;
  219. }
  220.  
  221. function subsection ($attributes, $content)
  222. {
  223.     $attributes = shortcode_atts(
  224.         array(
  225.             'color' => '',
  226.             'full_width' => FALSE,
  227.             'full_height' => FALSE,
  228.             'background' => FALSE,
  229.             'parallax' => FALSE,
  230.             'video' => FALSE,
  231.             'video_mp4' => FALSE,
  232.             'video_ogg' => FALSE,
  233.             'video_webm' => FALSE,
  234.  
  235.         ), $attributes);
  236.  
  237.     $output_type = ($attributes['color'] != '')?' color_'.$attributes['color']:'';
  238.     $full_width_type = ($attributes['full_width'] == 1)?' full_width':'';
  239.     $full_height_type = ($attributes['full_height'] == 1)?' full_height':'';
  240.     $background_style = '';
  241.     if ($attributes['background'] != '')
  242.     {
  243.         if (is_numeric($attributes['background']))
  244.         {
  245.             $img_id = preg_replace('/[^\d]/', '', $attributes['background']);
  246.             $img = wpb_getImageBySize(array( 'attach_id' => $img_id, 'thumb_size' => 'full' ));
  247.  
  248.             if ( $img != NULL )
  249.             {
  250.                 $img = wp_get_attachment_image_src( $img_id, 'full');
  251.                 $img = $img[0];
  252.             }
  253.  
  254.             $background_style = ' style="background-image: url('.$img.')"';
  255.         }
  256.         else
  257.         {
  258.             $background_style = ' style="background-image: url('.$attributes['background'].')"';
  259.         }
  260.  
  261.     }
  262.  
  263.     $parallax_class = '';
  264.     $parallax_data_output = '';
  265.     if ($attributes['parallax']) {
  266.         $parallax_class = ' with_parallax';
  267. //          $parallax_data_output = ' data-prlx-xpos="50%" data-prlx-speed="'.$attributes['parallax_speed'].'"';
  268.     }
  269.  
  270.     $video_html = $video_class = '';
  271.  
  272.     if ($attributes['video'] AND ($attributes['video_mp4'] != '' OR $attributes['video_ogg'] != '' OR $attributes['video_webm'] != '' )) {
  273.         $video_class = ' with_video';
  274.         $parallax_class = '';
  275.         $video_mp4_part = ($attributes['video_mp4'] != '')?'<source type="video/mp4" src="'.$attributes['video_mp4'].'"></source>':'';
  276.         $video_ogg_part = ($attributes['video_ogg'] != '')?'<source type="video/ogg" src="'.$attributes['video_ogg'].'"></source>':'';
  277.         $video_webm_part = ($attributes['video_webm'] != '')?'<source type="video/webm" src="'.$attributes['video_webm'].'"></source>':'';
  278.         $video_poster_part = ($attributes['background'] != '')?' poster="'.$attributes['background'].'"':'';
  279.         $video_img_part = ($attributes['background'] != '')?'<img src="'.$attributes['background'].'" alt="">':'';
  280.         $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>';
  281.     }
  282.  
  283.  
  284.     $output =   '<div class="l-subsection'.$full_height_type.$full_width_type.$output_type.$parallax_class.$video_class.'"'.$background_style.$parallax_data_output.'>'.
  285.         $video_html.
  286.         '<div class="l-subsection-h">'.
  287.         '<div class="l-subsection-hh g-html i-cf">'.
  288.         do_shortcode($content).
  289.         '</div>'.
  290.         '</div>'.
  291.         '</div>';
  292.  
  293.     return $output;
  294. }
  295.  
  296. function subsection_dummy ($attributes, $content)
  297. {
  298.     $attributes = shortcode_atts(
  299.         array(
  300.             'type' => FALSE,
  301.             'with' => FALSE,
  302.  
  303.         ), $attributes);
  304.  
  305.     $output = do_shortcode($content);
  306.  
  307.     return $output;
  308. }
Advertisement
Add Comment
Please, Sign In to add comment