ajayver

Untitled

Jul 9th, 2014
309
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.66 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_award_url') != '')
  58.                 {
  59.                     $client_new_tab = (rwmb_meta('us_award_new_tab') == 1)?' target="_blank"':'';
  60.                     $client_url = (rwmb_meta('us_award_url') != '')?rwmb_meta('us_award_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.     }
  89.  
  90.  
  91.  
  92. function award_register_meta_boxes()
  93. {
  94.     $meta_box = array(
  95.         'id' => 'award_settings',
  96.         'title' => 'Award Settings',
  97.         'pages' => array('us_award'),
  98.         'context' => 'normal',
  99.         'priority' => 'high',
  100.  
  101.         // List of meta fields
  102.         'fields' => array(
  103.             array(
  104.                 'name'      => 'Award URL',
  105.                 'id'        => 'us_award_url',
  106.                 'type'      => 'text',
  107.                 'std'       => '',
  108.             ),
  109.             array(
  110.                 'name'      => 'Open URL in new Tab',
  111.                 'id'        => 'us_award_new_tab',
  112.                 'type'      => 'checkbox',
  113.                 'std'       => false,
  114.             ),
  115.         ),
  116.     );
  117.  
  118.     if ( class_exists( 'RW_Meta_Box' ) ) {
  119.         new RW_Meta_Box( $meta_box );
  120.     }
  121. }
  122.  
  123. add_action( 'admin_init', 'award_register_meta_boxes' );
Advertisement
Add Comment
Please, Sign In to add comment