<?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_speakers]   
function xs_speakers($atts) {
    extract(shortcode_atts(array(
                    ), $atts));

    $html = '';
    global $within_section;
    // WP_Query arguments
    $args = array(
        'post_type' => 'speaker',
        '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();
            $name = (get_post_meta(get_the_ID(), 'xs_speaker_name', true) == '') ? (get_the_title()) : (get_post_meta(get_the_ID(), 'xs_speaker_name', true));
            $html .= '<div class="col-md-4 col-sm-6 col-xs-6">
                        <div class="section no-padding">
                                <figure>
                                        <img src="' . get_post_meta(get_the_ID(), 'xs_speaker_photo', true) . '" alt="Speaker" class="img-speaker" />
                                        <figcaption class="speaker-info">' . get_the_content() . '</figcaption>
                                </figure>
                                <div class="speaker clearfix">
                                        <div class="col-md-10 col-sm-9 col-xs-9">
                                                <h6>' . $name . '</h6>
                                                <p>' . get_post_meta(get_the_ID(), 'xs_speaker_title', true) . '</p>
                                        </div>
                                        <div class="col-md-2 col-sm-3 col-xs-3 readIcon"> <i class="fa fa-chevron-circle-down"></i> </div>
                                </div>
                        </div>
                </div>
                <!--end-col-md-4-->';
        }
    }
    // Restore original Post Data
    wp_reset_postdata();

    if ($within_section == 'y') {
        return '<div class="bottom-margin clearfix"></div><div class="row clearfix speaker-grid">' . $html . '</div>';
    } else {
        return '<div id="standalone-section" class="row clearfix speaker-grid">' . $html . '</div>';
    }
}

add_shortcode('xs_speakers', 'xs_speakers');
