Hy,
据我所知,您需要一个过滤器来显示属于特定术语列表的帖子。默认情况下,显示启用所有术语的所有帖子。为了禁止显示术语,需要将其从循环中排除。
<?php
// we get all the terms of the taxonomy
$terms = get_terms(\'mytaxonomy\');
/*
excludeTerms=term1,term2,term3
as a GET parameter created by the exclude form
*/
$excludeList = array();
if (isset($_GET[\'excludeTerms\']) && !empty($_GET[\'excludeTerms\'])) {
$excludeList = explode(\',\', $_GET[\'excludeTerms\']);
}
/*
how to display the available terms
the permalink is get_term_link($term, $taxonomy);
*/
$termList = \'\';
if (!empty($terms) && !is_wp_error($terms)) {
echo "<ul>";
foreach ($terms as $term) {
if (!in_array($term->name, $excludeList)) {
echo "<li class=\'enabled-term\'>" . $term->name . "</li>";
if ($termList == \'\') {
$termList = $term->name;
} else {
$termList .= \', \' . $term->name;
}
} else {
echo "<li class=\'disabled-term\'>" . $term->name . "</li>";
}
}
echo "</ul>";
}
if ($termList != \'\') {
$args = array(
\'post_type\' => \'posttype\',
\'mytaxonomy\' => $termList
);
} else {
$args = array(
\'post_type\' => \'posttype\'
);
}
query_posts($args);
while (have_posts()) {
the_post();
the_title();
echo "<br />";
}
?>
<style>
.enabled-term, .disabled-term {
cursor: pointer;
}
.disabled-term {
color: #ddd;
}
</style>
<script>
jQuery(document).ready(function ($) {
$(\'.enabled-term\').live(\'click\', function () {
// so that one term remains enabled
if ($(\'.enabled-term\').length == 1)
return;
$(this).removeClass(\'enabled-term\').addClass(\'disabled-term\');
navigate();
});
$(\'.disabled-term\').live(\'click\', function () {
$(this).removeClass(\'disabled-term\').addClass(\'enabled-term\');
navigate();
});
function navigate() {
list = $(\'.disabled-term\');
excludeList = \'\';
for (i = 0; i < list.length; i++) {
if (excludeList == \'\')
excludeList = $(list[i]).text();
else
excludeList += \',\' + $(list[i]).text();
}
window.location = window.location.origin +
window.location.pathname +
\'?excludeTerms=\' + excludeList;
};
}(jQuery));
</script>
http://codex.wordpress.org/Function_Reference/get_terms 对于术语列表
http://codex.wordpress.org/query_posts 用于循环(示例5用于税务和条款)
希望这有帮助。