ajayver

Untitled

Jul 4th, 2014
286
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.00 KB | None | 0 0
  1. add_action( 'init', 'create_awards_post_type' );
  2. function create_awards_post_type() {
  3.     register_post_type( 'us_award',
  4.         array(
  5.             'labels' => array(
  6.                 'name' => 'Awards',
  7.                 'singular_name' => 'Award',
  8.                 'add_new' => 'Add Award',
  9.             ),
  10.             'public' => true,
  11.             'publicly_queryable' => false,
  12.             'has_archive' => true,
  13.             'supports' => array('title', 'thumbnail'),
  14.             'can_export' => true,
  15.         )
  16.     );
  17. }
  18.  
  19. add_shortcode('awards', 'awards');
  20.  
  21. function awards($attributes, $content)
  22.     {
  23.         $attributes = shortcode_atts(
  24.             array(
  25.                 'amount' => 1000,
  26.                 'auto_scroll' => false,
  27.                 'interval' => 1,
  28.             ), $attributes);
  29.  
  30.         $args = array(
  31.             'post_type' => 'us_award',
  32.             'paged' => 1,
  33.             'posts_per_page' => $attributes['amount'],
  34.         );
  35.  
  36.         $rand_id = rand(100000, 999999);
  37.  
  38.         $auto_scroll = ($attributes['auto_scroll'] == 1 OR $attributes['auto_scroll'] == 'yes')?'true':'false';
  39.         $interval = intval($attributes['interval']);
  40.         if ($interval < 1) {
  41.             $interval = 1;
  42.         }
  43.         $interval = $interval*1000;
  44.  
  45.         $cleints = new WP_Query($args);
  46.  
  47.         $output =   '<div class="w-clients type_carousel columns_5 clients_'.$rand_id.'">
  48.                             <div class="w-clients-h">
  49.                                 <div class="w-clients-list">
  50.                                     <div class="w-clients-list-h">';
  51.  
  52.         while($cleints->have_posts())
  53.         {
  54.             $cleints->the_post();
  55.             if(has_post_thumbnail())
  56.             {
  57.                 if (rwmb_meta('us_client_url') != '')
  58.                 {
  59.                     $client_new_tab = (rwmb_meta('us_client_new_tab') == 1)?' target="_blank"':'';
  60.                     $client_url = (rwmb_meta('us_client_url') != '')?rwmb_meta('us_client_url'):'javascript:void(0);';
  61.                     $client_url = (substr($client_url, 0, 4) == 'http' OR $client_url == 'javascript:void(0);' OR $client_url == '#')?$client_url:'//'.$client_url;
  62.                     $output .=          '<a class="w-clients-item" href="'.$client_url.'"'.$client_new_tab.'>'.
  63.                         get_the_post_thumbnail(get_the_ID(), 'carousel-thumb').
  64.                         '</a>';
  65.                 }
  66.                 else
  67.                 {
  68.                     $output .=          '<div class="w-clients-item">'.
  69.                         get_the_post_thumbnail(get_the_ID(), 'carousel-thumb').
  70.                         '</div>';
  71.                 }
  72.  
  73.             }
  74.         }
  75.  
  76.         $output .=                  '</div>
  77.                                 </div>
  78.                                 <a class="w-clients-nav to_prev disabled" href="javascript:void(0)" title=""></a>
  79.                                 <a class="w-clients-nav to_next" href="javascript:void(0)" title=""></a>
  80.                             </div>
  81.                         </div>';
  82.         $output .= '<script type="text/javascript">
  83.                         jQuery(window).load(function() {
  84.                             jQuery(".clients_'.$rand_id.'").carousello({use3d: false, autoScroll: '.$auto_scroll.',interval: '.$interval.'});
  85.                         });
  86.                     </script>';
  87.         return $output;
  88.     }
Advertisement
Add Comment
Please, Sign In to add comment