我目前正使用Posts
内的代码在我的Team
类别中显示Page.php
该功能。
我还在我的Sidebar.php
中列出了“团队”的子类别,也列在下面。
我的Sidebar
是否可以使用表单让用户选择要显示帖子的子类别?
直接访问/?page_id=9&team=3,4
会显示Posts
中的Team 3 & 4
,但我想知道是否可以使用表单让用户选择要显示的帖子。
非常感谢您提出的任何指示。
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;
}
?>
答案 0 :(得分:0)
您可以在侧边栏中添加一个选择框,然后更改page.php中div的内容;
像:
page.php文件:
<div id="content"></div>
Subpage.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
创建插件和小部件将是一个更稳定的解决方案