shortcodes-course.php 3.62 KB
<?php 

add_shortcode('course-list', 'course_list');


function course_list(){

    $custom_args = array(
        'post_type' => 'sfwd-courses',
        'posts_per_page' => -1,
        'paged' => 1,
    );
    $custom_query = new \WP_Query($custom_args);
      
    ob_start(); 
    $uniqid = uniqid();
      if ($custom_query->have_posts()):?>
        <div class="course-list">
            <label for="quicksearch">Search programs:</label><input type="text" id="quicksearch" placeholder="" />
            <div class="filters">
            <a href="#" id="filter-more">FILTERS <span aria-hidden="true" class="glyphicon glyphicon-chevron-up"></span></a>
            <div class="filter-group">
                <div class="category-filter-group">
                  <?php $terms = get_terms( array( 'taxonomy' =>  'ld_course_category' ,'parent'   => 0) );
                        foreach($terms as $term){ ?>
                            <div class="category-filter"> <input id="<?php echo $term->slug ; ?>" value=".<?php echo $term->slug ; ?>" type="checkbox" class="sr-only"><label for="<?php echo $term->slug ; ?>"><?php echo $term->name ; ?></label></div>
                      <?php }; ?>
                </div>
                <div class="btn-group sort-button-group  align-self-end"> 
                  <button class="btn btn-light" data-sort-direction="asc" data-sort-value="coursename" type="button">Name <span aria-hidden="true" class="glyphicon glyphicon-chevron-up"></span></button> 
                  <button class="btn btn-light" data-sort-direction="asc" data-sort-value="coursedate" type="button">Date <span aria-hidden="true" class="glyphicon glyphicon-chevron-up"></span></button> 
                </div>
            </div>
            </div>
            <div class="grid course">
                <?php while ($custom_query->have_posts()): $custom_query->the_post();  
                            echo course_card(get_the_ID());
                      endwhile; ?>
            </div>
          </div>       
      <?php endif;
  wp_reset_query();
  $output = ob_get_clean(); 
  return $output;
}



function course_card($id){

  ob_start(); 
  $post = get_post($id);
  $text = str_replace(']]>', ']]&gt;', apply_filters( 'the_content', strip_shortcodes($post->post_content)));
  $excerpt_length = apply_filters( 'excerpt_length', 20 );
  $text = wp_trim_words( $text, $excerpt_length, ' ...' );
  $categories = get_the_terms( $id, 'ld_course_category' );
  $cat =""; foreach( $categories as $category ) { $cat .= " ".$category->slug; }; ?>

    <div data-name="<?php echo $post->post_name; ?>" data-ticks="<?php echo get_post_time('U',false, $id ); ?>" class="element-item <?php echo $cat; ?> " data-category="<?php echo $cat; ?>">
        <article id="post-<?php echo $id; ?>" class="post post-<?php echo $id; ?> sfwd-courses type-sfwd-courses">
          <div class="card">
                <div class="thumbnail"><div class="ribbon"><?php echo get_post_meta( $id, '_learndash_course_grid_custom_ribbon_text', true);?></div>
                        <div class="image">
                            <?php echo get_the_post_thumbnail($id, 'full' ); ?>
                        </div>
                </div>
                <div class="content">
                <h3 class="entry-title"><?php echo $post->post_title; ?></h3>
                    <div class="entry-content">
                        <p><?php echo $text; ?></p>
                    </div>
                    <a class="btn" role="button" href="<?php echo get_permalink($id); ?>" rel="bookmark">LEARN MORE</a>

                </div>
            </div>
        </article>
    </div>   

<?php
  $output = ob_get_clean();
  return $output;
}