<?php

/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

// [xs_sponsor]   
function xs_sponsor($atts) {
    extract(shortcode_atts(array(
        'category' => '',
                    ), $atts));

    global $post, $within_section;
    $html = '';
    // WP_Query arguments
    $args = array(
        'post_type' => 'xs_sponsor',
        'sponsor_cat'=>$category,
        //'orderby' => 'menu_order',
        'order' => 'DSC',
        
    );
    // The Query
    $query = new WP_Query($args);

    // The Loop
    if ($query->have_posts()) {
        while ($query->have_posts()) {
            $query->the_post();
            $html .= '<a href="' . esc_url(get_post_meta($post->ID, 'xs_sponsor_link', true)) . '" title="' . $post->post_title . '"> <img class="img-responsive" src="' . get_post_meta($post->ID, 'xs_sponsor_image', true) . '" alt="' . $post->post_title . '" /> </a>';
        }
    }
    // Restore original Post Data
    wp_reset_postdata();
    $klass = ($within_section == 'y') ? ('section xs-section bottom-margin clearfix') : ('clearfix');
    return '<div class="' . $klass . '"><div class="partner clearfix">' . $html . '</div></div>';
}

add_shortcode('xs_sponsor', 'xs_sponsor');