Advertisement
Guest User

themeum-advertiser

a guest
Jul 1st, 2016
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.55 KB | None | 0 0
  1. <?php
  2. if ( ! defined( 'ABSPATH' ) ) {
  3.     exit; // Exit if accessed directly
  4. }
  5.  
  6. //Performer Scroller
  7. add_shortcode( 'themeum_advertisement_shortcode', function($atts, $content = null){
  8.  
  9.     extract(shortcode_atts(array(
  10.         'title'             => '',
  11.         'ads_type'          => 'ads_cat',
  12.         'advertisement_cat' => 'themeumall',
  13.         'advertisement_post'=> ''
  14.         'class'             => ''
  15.         ), $atts));
  16.  
  17.  
  18.     global $post;
  19.  
  20.     $args = '';  
  21.  
  22.     if( $ads_type == "ads_cat" ){
  23.         if( $advertisement_cat != 'themeumall' ){
  24.             $args = array(
  25.                         'post_type' => 'advertisement',
  26.                         'tax_query' => array(
  27.                                             array(
  28.                                                 'taxonomy' => 'advertisement_cat',
  29.                                                 'field'    => 'slug',
  30.                                                 'terms'    => $advertisement_cat,
  31.                                             ),
  32.                                         ),
  33.                         'posts_per_page'   => 1,
  34.                         'orderby'          => 'rand',
  35.                         'post_status'      => 'publish',
  36.                     );
  37.         }else{
  38.             $args = array(
  39.                         'post_type' => 'advertisement',
  40.                         'posts_per_page'   => 1,
  41.                         'orderby'          => 'rand',
  42.                         'post_status'      => 'publish',
  43.                         );
  44.         }
  45.     }else{
  46.         $args = array(
  47.                         'name'        => $advertisement_post,
  48.                         'post_type'   => 'advertisement',
  49.                         'post_status' => 'publish',
  50.                         'posts_per_page' => 1
  51.                     );
  52.     }  
  53.    
  54.  
  55.     $data = get_posts( $args );
  56.  
  57.     $output = '<div class="themeum-ads '.esc_attr( $class ).' ">';
  58.  
  59.     if($title) {
  60.         $output .= '<h3 class="ads-style">' . esc_attr($title) . '</h3>';
  61.     }
  62.     foreach ( $data as $key=>$post ) {
  63.         setup_postdata( $post );
  64.  
  65.         $link = get_post_meta( get_the_ID(), 'themeum_link', true);
  66.         if( $link != '' ){ $output .= '<a href="'.esc_url($link).'">'; }
  67.         $output .= get_the_post_thumbnail( $post->ID ,'full', array('class' => 'img-responsive') );
  68.         if( $link != '' ){ $output .= '</a>'; }
  69.  
  70.     }
  71.     wp_reset_postdata();
  72.     $output .= '</div>';
  73.  
  74.     return $output;
  75. });
  76.  
  77.  
  78. //Visual Composer
  79. if (class_exists('WPBakeryVisualComposerAbstract')) {
  80.     vc_map(array(
  81.         "name" => __("Advertisement Shortcode", "themeum-advertiser"),
  82.         "base" => "themeum_advertisement_shortcode",
  83.         'icon' => 'icon-wpb-advertisement',
  84.         "class" => "",
  85.         "description" => __("Themeum Advertisement","themeum-advertiser"),
  86.         "category" => __("New Edge", "themeum-advertiser"),
  87.         "params" => array(
  88.  
  89.             array(
  90.                 "type" => "textfield",
  91.                 "heading" => __("Title", "themeum-advertiser"),
  92.                 "param_name" => "title",
  93.                 "description" => __("Title of Advertisement", "themeum-advertiser"),
  94.                 "value" => "",
  95.                 "admin_label"=>true,
  96.                 ),
  97.  
  98.  
  99.  
  100.             // Dropdown
  101.             array(
  102.                 "type" => "dropdown",
  103.                 "class" => "",
  104.                 "heading" => __("Ads Type","themeum-advertiser"),
  105.                 "param_name" => "ads_type",
  106.                 "value" => array(
  107.                     "Category" => "ads_cat",
  108.                     "Single Post" => "ads_single",
  109.                     ),
  110.                 ),
  111.            
  112.  
  113.             array(
  114.                 "type"          => "dropdown",
  115.                 "heading"       => __("Select Advertisement Category:","themeum-advertiser"),
  116.                 "param_name"    => "advertisement_cat",
  117.                 "value"         => themeum_cat_list( 'advertisement_cat' ),
  118.                 "dependency"    => Array("element" => "ads_type","value" => array("ads_cat")),
  119.                 ),
  120.  
  121.  
  122.             array(
  123.                 "type"          => "dropdown",
  124.                 "heading"       => __("Select Advertisement Post:","themeum-advertiser"),
  125.                 "param_name"    => "advertisement_post",
  126.                 "value"         => themeum_all_post_list(),
  127.                 "dependency"    => Array("element" => "ads_type","value" => array("ads_single")),
  128.                 ),
  129.             array(
  130.                 "type" => "textfield",
  131.                 "heading" => esc_html__("Custom Class", 'newedge'),
  132.                 "param_name" => "class",
  133.                 "value" => "",
  134.             )
  135.  
  136.  
  137.             )
  138.  
  139. ));
  140. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement