2

这是一个mixitup插件过滤。我只想使用两个类别来过滤帖子。*更新,我修复了过滤菜单,但仍然无法显示这两个类别的帖子。

我的类别是“事件”(id=3)和“新闻”(id=4)。

更新

我通过使用 include 在过滤菜单中部分工作

<?php 
        $terms = get_terms('category', 'include=6,7&hide_empty=0'); // get all categories, but you can use any taxonomy
        $count = count($terms); //How many are they?
        if ( $count > 0 ){  //If there are more than 0 terms
            foreach ( $terms as $term ) {  //for each term:
                echo "<li class=".filter." data-filter='.".$term->slug."'>" . $term->name . "</li>\n";
                //create a list item with the current term slug for sorting, and name for label
            }
        } 
    ?>

但我无法让它显示这两个类别的帖子

<?php 
$args = array (
    'post_type'              => array( 'posts' ),
    'order'                  => 'ASC',
);

 $the_query = new WP_Query( $args ); //Check the WP_Query docs to see how you can limit which posts to display ?>
<?php if ( $the_query->have_posts() ) : ?>
    <div id="isotope-list">
    <?php while ( $the_query->have_posts() ) : $the_query->the_post(); 
    $termsArray = get_the_terms( $post->ID, 'events');  //Get the terms for this particular item
    $termsString = ""; //initialize the string that will contain the terms
        foreach ( $termsArray as $term ) { // for each term 
            $termsString .= $term->slug.' '; //create a string that has all the slugs 
        }
    ?> 
    <div class="<?php echo $termsString; ?> item mix">
4

1 回答 1

1

终于,想通了!这一切都在 wp_query 中。我需要补充的是

$the_query = new WP_Query( 'cat=6,7');

而且我可以按这两个类别显示帖子...

于 2016-02-23T02:46:58.803 回答