shortcodes-resources.php 3.09 KB
<?php 

add_shortcode('resources-list', 'resources_list');


function resources_list(){

    $custom_args = array(
        'post_type' => 'attachment',
        'posts_per_page' => -1,
        'paged' => 1,
        'post_status' => 'any',
    );
    $custom_query = new \WP_Query($custom_args);
   
    ob_start(); 
    $uniqid = uniqid();
      if ($custom_query->have_posts()):
    ?>
        <div class="course-list resources">
            <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' =>  'media-category' ,'parent'   => 17) );
                        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 }; ?>
                      <?php $terms = get_terms( array( 'taxonomy' =>  'media-category' ,'parent'   => 22) );
                        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 resources">
                <?php while ($custom_query->have_posts()): $custom_query->the_post();  

                            echo resources(get_the_ID());
                      endwhile; ?>
            </div>
          </div>       
      <?php endif;
  wp_reset_query();
  $output = ob_get_clean(); 
  return $output;
}



function resources($id){

  ob_start(); 
  $post = get_post($id);
  $categories = get_the_terms( $id, 'media-category' );
  $cat ="";
  if(is_array( $categories)){
    foreach( $categories as $category ) { $cat .= " ".$category->slug; };
  } ?>

 <div class="table-like__item element-item <?php echo $cat; ?> " data-category="<?php echo $cat; ?>">
  <a role="button" href="<?php echo get_permalink($id); ?>"><?php echo $post->post_title; ?></a><br>
    <?php echo wp_get_attachment_caption($id) ?>
  </div>
<?php
  $output = ob_get_clean();
  return $output;
}