Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $current_cat = get_query_var('cat');
- $tag_slugs = array();
- global $query_string;
- query_posts( $query_string);
- // first loop to get all post tag (area) slugs
- while ( have_posts() ) {
- the_post();
- $tags = get_the_tags();
- if($tags) {
- foreach ($tags as $tag) {
- $tag_slugs[] = $tag->slug;
- }
- }
- }
- // remove duplicate tag slugs and sort them alphabetically
- $tag_slugs = array_unique($tag_slugs);
- sort($tag_slugs);
- ?>
- <?php
- // if there are tags show the form
- if(!empty($tag_slugs)) :
- ?>
- <form method="get" id="tag_order">
- <select name="select_tag">
- <option value="alltags" <?php selected( $_GET['area'],'alltags', 1 ); ?> onClick='window.location = "<?php echo get_category_link( $current_cat ); ?>"' >All Areas</option>
- <?
- foreach ( $tag_slugs as $tag_slug ) {
- $the_tag = get_term_by( 'slug', $tag_slug, 'post_tag' );
- echo '<option value="'.$the_tag->slug.'"'.selected($_GET['area'],$the_tag->slug, 1 );
- echo ' onClick=\'window.location = "'.get_category_link( $current_cat ).'?area='.$the_tag->slug.'"; return false;\'>'.$the_tag->name.'</option>';
- }
- ?>
- </select>
- </form>
- <?php endif; ?>
- <?php
- // very important to reset the query
- wp_reset_query(); ?>
- <?php
- if(isset($_GET['area']) && $_GET['area']) {
- // an areay was selected
- global $query_string;
- query_posts( $query_string.'&tag='.$_GET['area']);
- }
- ?>
- <!-- second loop -->
- <?php if ( have_posts() ) : ?>
- <?php while (have_posts()) : the_post(); ?>
- <!-- rest of your loop -->
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement