Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_action( 'init', 'create_awards_post_type' );
- function create_awards_post_type() {
- register_post_type( 'us_award',
- array(
- 'labels' => array(
- 'name' => 'Awards',
- 'singular_name' => 'Award',
- 'add_new' => 'Add Award',
- ),
- 'public' => true,
- 'publicly_queryable' => false,
- 'has_archive' => true,
- 'supports' => array('title', 'thumbnail'),
- 'can_export' => true,
- )
- );
- }
- add_shortcode('awards', 'awards');
- function awards($attributes, $content)
- {
- $attributes = shortcode_atts(
- array(
- 'amount' => 1000,
- 'auto_scroll' => false,
- 'interval' => 1,
- ), $attributes);
- $args = array(
- 'post_type' => 'us_award',
- 'paged' => 1,
- 'posts_per_page' => $attributes['amount'],
- );
- $rand_id = rand(100000, 999999);
- $auto_scroll = ($attributes['auto_scroll'] == 1 OR $attributes['auto_scroll'] == 'yes')?'true':'false';
- $interval = intval($attributes['interval']);
- if ($interval < 1) {
- $interval = 1;
- }
- $interval = $interval*1000;
- $cleints = new WP_Query($args);
- $output = '<div class="w-clients type_carousel columns_5 clients_'.$rand_id.'">
- <div class="w-clients-h">
- <div class="w-clients-list">
- <div class="w-clients-list-h">';
- while($cleints->have_posts())
- {
- $cleints->the_post();
- if(has_post_thumbnail())
- {
- if (rwmb_meta('us_award_url') != '')
- {
- $client_new_tab = (rwmb_meta('us_award_new_tab') == 1)?' target="_blank"':'';
- $client_url = (rwmb_meta('us_award_url') != '')?rwmb_meta('us_award_url'):'javascript:void(0);';
- $client_url = (substr($client_url, 0, 4) == 'http' OR $client_url == 'javascript:void(0);' OR $client_url == '#')?$client_url:'//'.$client_url;
- $output .= '<a class="w-clients-item" href="'.$client_url.'"'.$client_new_tab.'>'.
- get_the_post_thumbnail(get_the_ID(), 'carousel-thumb').
- '</a>';
- }
- else
- {
- $output .= '<div class="w-clients-item">'.
- get_the_post_thumbnail(get_the_ID(), 'carousel-thumb').
- '</div>';
- }
- }
- }
- $output .= '</div>
- </div>
- <a class="w-clients-nav to_prev disabled" href="javascript:void(0)" title=""></a>
- <a class="w-clients-nav to_next" href="javascript:void(0)" title=""></a>
- </div>
- </div>';
- $output .= '<script type="text/javascript">
- jQuery(window).load(function() {
- jQuery(".clients_'.$rand_id.'").carousello({use3d: false, autoScroll: '.$auto_scroll.',interval: '.$interval.'});
- });
- </script>';
- return $output;
- }
- function award_register_meta_boxes()
- {
- $meta_box = array(
- 'id' => 'award_settings',
- 'title' => 'Award Settings',
- 'pages' => array('us_award'),
- 'context' => 'normal',
- 'priority' => 'high',
- // List of meta fields
- 'fields' => array(
- array(
- 'name' => 'Award URL',
- 'id' => 'us_award_url',
- 'type' => 'text',
- 'std' => '',
- ),
- array(
- 'name' => 'Open URL in new Tab',
- 'id' => 'us_award_new_tab',
- 'type' => 'checkbox',
- 'std' => false,
- ),
- ),
- );
- if ( class_exists( 'RW_Meta_Box' ) ) {
- new RW_Meta_Box( $meta_box );
- }
- }
- add_action( 'admin_init', 'award_register_meta_boxes' );
Advertisement
Add Comment
Please, Sign In to add comment