Advertisement
Guest User

Untitled

a guest
Jan 3rd, 2012
639
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. <?php
  2. $current_cat = get_query_var('cat');
  3. $tag_slugs = array();
  4. global $query_string;
  5. query_posts( $query_string);
  6.  
  7. // first loop to get all post tag (area) slugs
  8. while ( have_posts() ) {
  9. the_post();
  10. $tags = get_the_tags();
  11. if($tags) {
  12. foreach ($tags as $tag) {
  13. $tag_slugs[] = $tag->slug;
  14. }
  15. }
  16. }
  17. // remove duplicate tag slugs and sort them alphabetically
  18. $tag_slugs = array_unique($tag_slugs);
  19. sort($tag_slugs);
  20. ?>
  21.  
  22. <?php
  23. // if there are tags show the form
  24. if(!empty($tag_slugs)) :
  25. ?>
  26. <form method="get" id="tag_order">
  27. <select name="select_tag">
  28. <option value="alltags" <?php selected( $_GET['area'],'alltags', 1 ); ?> onClick='window.location = "<?php echo get_category_link( $current_cat ); ?>"' >All Areas</option>
  29. <?
  30. foreach ( $tag_slugs as $tag_slug ) {
  31.  
  32. $the_tag = get_term_by( 'slug', $tag_slug, 'post_tag' );
  33.  
  34. echo '<option value="'.$the_tag->slug.'"'.selected($_GET['area'],$the_tag->slug, 1 );
  35. echo ' onClick=\'window.location = "'.get_category_link( $current_cat ).'?area='.$the_tag->slug.'"; return false;\'>'.$the_tag->name.'</option>';
  36. }
  37. ?>
  38. </select>
  39. </form>
  40. <?php endif; ?>
  41. <?php
  42. // very important to reset the query
  43. wp_reset_query(); ?>
  44. <?php
  45. if(isset($_GET['area']) && $_GET['area']) {
  46. // an areay was selected
  47. global $query_string;
  48. query_posts( $query_string.'&tag='.$_GET['area']);
  49. }
  50. ?>
  51.  
  52. <!-- second loop -->
  53. <?php if ( have_posts() ) : ?>
  54. <?php while (have_posts()) : the_post(); ?>
  55.  
  56. <!-- rest of your loop -->
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement