0

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;
    }
?>
4

1 回答 1

0

您可以在侧边栏中添加一个选择框并更改 page.php 中 div 的内容;

喜欢:

页面.php:

<div id="content"></div>

子页面.php:

<select id="category">
    <option value="">Select your team</option>
    <option value="Team 1">Team 1</option>
    <option value="Team 2">Team 2</option>
    <option value="Team 3">Team 3</option>
</select>
<script>
$('#category').change(function() {
        if(this.value) $('#content').html(this.value);
});
 </script>  

您可以使用 ajax 请求来获取您的帖子,而不是向您的 div 添加文本。也许从RSS阅读帖子,看;http://wordpress.org/support/topic/rss-feed-of-post-category

创建插件和小部件将是一个更稳定的解决方案

于 2013-05-02T20:53:59.780 回答