Advertisement
Guest User

Untitled

a guest
May 25th, 2014
650
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.96 KB | None | 0 0
  1. <article>
  2. <?php
  3. /**
  4.  * Template name: AJAX Post Filter by Taxonomy
  5.  *
  6.  */
  7.  
  8. $args = array(
  9.     'post_type' => 'post',
  10.     'posts_per_page' => 10,
  11. );
  12.  
  13. $query = new WP_Query( $args );
  14.  
  15. function tags_filter() {
  16.     $tax = 'post_tag';
  17.     $terms = get_terms( $tax );
  18.     $count = count( $terms );
  19.  
  20.     if ( $count > 0 ): ?>
  21.         <div class="post-tags">
  22.         <?php
  23.         foreach ( $terms as $term ) {
  24.             $term_link = get_term_link( $term, $tax );
  25.             echo '<a href="' . $term_link . '" class="tax-filter" title="' . $term->slug . '">' . $term->name . '</a> ';
  26.         } ?>
  27.         </div>
  28.     <?php endif;
  29. }
  30.  
  31. tags_filter();
  32.  
  33. if ( $query->have_posts() ): ?>
  34. <div class="tagged-posts">
  35.     <?php while ( $query->have_posts() ) : $query->the_post(); ?>
  36.    
  37.     <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
  38.     <?php the_excerpt(); ?>
  39.  
  40.     <?php endwhile; ?>
  41. </div>
  42.  
  43. <?php else: ?>
  44.     <div class="tagged-posts">
  45.         <h2>No posts found</h2>
  46.     </div>
  47. <?php endif; ?>
  48. </article>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement