I am currently displaying Posts
that feature in my Team
category using the code inside Page.php
.
I'm also listing the sub-categories of 'Team' in my Sidebar.php
, also listed below.
Is it possible in my Sidebar
that I can have a form that lets the user choose which sub-categories to show posts from?
Visiting /?page_id=9&team=3,4
directly will show Posts
from Team 3 & 4
, but I wonder if I can use a Form to let the user choose which posts to display.
Many thanks for any pointers with this.
Page.php:
<?php
$type = 'team';
$args=array(
'post_type' => $type,
'post_status' => 'publish',
'posts_per_page' => -1,
'caller_get_posts'=> 1,
'cat'=> 3
);
$my_query = null;
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<h2>Team Name: <?php the_title(); ?></h2>
<?php
endwhile;
}
wp_reset_query(); // Restore global post data stomped by the_post().
?>
Sidebar.php:
<?php
$categories= get_categories('child_of=2');
foreach ($categories as $category) {
$option = '<li><label>'.$category->cat_name.'</label><input type="checkbox" name="team" value="'.$category->term_id.'" style="float:right" /></li>';
echo $option;
}
?>