User selecting multiple categories
-
Hey!
I’m rather new to wordpress theme development, and I’m currently making a site were I want the user to be able to filter posts by selecting one or multiple categories, but I can’t find a solution which works.
To list the different categories I use:
<?php wp_list_categories('child_of=9&title_li=&hide_empty=0&orderby=term_group'); ?>Example of the list of categories and the output:
Food
- Hot food
- Desserts
- Fruit
Countries
- Germany
- Sweden
- Japan
Month
- January
- November
- December
So the user can select ex. Hot food, Sweden, and January, and only see the posts posted under those categories.
The link would look something like this: http://www.example.com/category/hotfood/sweden/january/
This is the code for the page. (category.php)
<?php get_header(); ?> <?php if (is_page('newsarchive')): $temp = $wp_query; $wp_query= null; $wp_query = new WP_Query(); $wp_query->query('showposts=8'.'&paged='.$paged); endif; ?> <div class="container" id="nyheter"> <div class="sixteen columns"> <h2 class="sectionTitle" id="nyheterTitle"> Nyheter </h2> <div class="sixteen columns flexslider" id="slider"> <ul class="slides"> <li> <img src="slide2.jpg" /> </li> <li> <img src="slide2.jpg" /> </li> <li> <img src="slide3.jpg" /> </li> </ul> </div> <!-- end sixteen columns flexslider --> <div class="filterGrupperContainter"> <h3 class="filterNyheterType two columns" id="grupperFilter"> Gruppe</h3> <h3 class="filterNyheterCurrent two columns" id="grupperCurrent"> <?php single_cat_title(); ?> </h3> <ul id="filterGrupper" class="sixteen columns"> <?php wp_list_categories('exclude=11,9,5&title_li=&hide_empty=0'); wp_list_categories('child_of=5&title_li=&hide_empty=0&orderby=term_group'); ?> </ul> <!-- end filterGrupper --> </div> <!-- end filterGrupperContainer --> <div id="filterSidebar" class="fr"> <div class="filterContainter"> <h3 class="filterNyheterType two columns omraade" id="grupperFilter"> Område</h3> <h3 class="filterNyheterCurrent two columns omraadeCurrent" id="grupperCurrent"> Snertingdalen </h3> <ul class="sidebarFilterLinks"> <?php wp_list_categories('child_of=9&title_li=&hide_empty=0&orderby=term_group'); ?> </ul> <!-- end sidebarFilterLinks --> </div> <!-- end filterGrupperContainer --> <div class="filterContainter"> <h3 class="filterNyheterType two columns omraade" id="grupperFilter"> Måned</h3> <h3 class="filterNyheterCurrent two columns omraadeCurrent" id="grupperCurrent"> September </h3> <ul class="sidebarFilterLinks"> <?php wp_get_archives( array( 'type' => 'monthly', 'limit' => 12 ) ); ?> </ul> <!-- end sidebarFilterLinks --> </div> <!-- end filterGrupperContainer --> <div class="filterContainter"> <h3 class="filterNyheterType two columns omraade" id="grupperFilter"> År</h3> <h3 class="filterNyheterCurrent two columns omraadeCurrent" id="grupperCurrent"> Alle </h3> <ul class="sidebarFilterLinks"> <?php wp_get_archives( array( 'type' => 'yearly', 'limit' => 5 ) ); ?> </ul> <!-- end sidebarFilterLinks --> </div> <!-- end filterGrupperContainer --> </div> <!-- end filterSidebar --> <div class="thirteen columns omega" id="nyheterContainer"> <?php if( have_posts() ) : while (have_posts() ) : the_post(); ?> <div class="six columns nyhet" id="firstArticleNyheter"> <figure> <a href="<?php the_permalink() ?>"> <?php if ( function_exists('has_post_thumbnail') && has_post_thumbnail($post->ID) ) { $thumbnail = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), full ); the_post_thumbnail( 'archiveThumb' ); ?> <?php }else{ ?> <img src="images/defaultBilde940px.jpg" height="255px" width="340px" /> <?php } ?> </a> </figure> <span class="date"> <?php the_time('F jS, Y') ?> </span> <h3 class="newsTitle"> <?php the_title(); ?> </h3> <p class="newsText"> <?php the_excerpt(); ?> </p> <div class="newsLink"> <a href="<?php the_permalink() ?>" title="Les Mer" class="lesMerLink"> Les Mer </a> </div> </div> <!-- end six column --> <?php endwhile; else: ?> <p> Beklager, det ser ut som om det har skjedd en feil. </p> <?php endif; ?> <div id="pages" class="thirteen columns"> <?php global $wp_query; $total_pages = $wp_query->max_num_pages; if ($total_pages > 1){ $current_page = max(1, get_query_var('paged')); echo '<div class="page_nav">'; echo paginate_links(array( 'base' => get_pagenum_link(1) . '%_%', 'format' => '/page/%#%', 'current' => $current_page, 'total' => $total_pages, 'prev_text' => 'Prev', 'next_text' => 'Next' )); echo '</div>'; } ?> </div> </div> <!-- end nyheterContainer --> </div> <!-- end sixteen columns --> </div> <!-- end nyheter --> <?php get_footer (); ?>Hope you’ll have a great new year!
The topic ‘User selecting multiple categories’ is closed to new replies.