使用 'new WP_Query' 标注单个类别



我在循环中排除了一个类别(效果很好),现在我想在下面的这个循环中调用相同的类别。(以便它显示在页面底部。我希望一双新鲜的眼睛可以帮助我告诉我这里发生了什么。它没有显示任何东西。我正在使用"新WP_Query"来引入单个类别......在这里:

<?php // Begin Recent Sold loop of 3 ?>
<?php $args = new WP_Query('cat=367'); // category 367
    while($args->have_posts()) : $args->the_post(); ?>
<div class="category">
    <h2 class="artist-name">
        <?php echo '<a href="' . get_category_link( $category->cat_ID ) . '">' . $category->name . '</a> <a class="viewall" href="' . get_category_link( $category->cat_ID ) . '">VIEW ALL</a>'; ?></h2>
    <ul class="subcats">
    <?php
        $cats = wp_list_categories('orderby=name&title_li=&use_desc_for_title=0&depth=1&echo=0&show_count=1&child_of='.$category->cat_ID);
        if (!strpos($cats,'No categories') ){
        echo $cats;
        }
    ?>
    </ul>

    <div class="row clearfix">

    <?php $query = array(
        'post_type' => 'work',
        'posts_per_page' => '3',
        'orderby' => 'post_title',
        'order' => 'ASC',
        'cat' => $category->cat_ID,
            );
        query_posts($query);
    if ( have_posts() ) while ( have_posts() ) : the_post(); 
        $rows = get_field('images');
        if(get_the_post_thumbnail()){
        echo '<div class="four column work"><a href="'.get_permalink().'">';
        echo get_the_post_thumbnail($post_id, 'medium');
        echo '</a></div>';
        } else {
            if($rows)
                {
                foreach($rows as $row)
                    {
                    echo '<div class="four column work"><a href="'.get_permalink().'">';
                    echo '<img src="'. $row['image']['sizes']['medium'] . '" class="shadowed forced" alt="'.$row['image']['alt'].'">';
                    echo '</a></div>';
                    } ?>

                <?php }
            }
            ?>
    <?php endwhile; wp_reset_query(); ?>
    </div><!-- .row -->
</div><!-- .category -->
<?php endwhile; ?>
<?php wp_reset_postdata(); // reset the query ?>
    <?php // End Recent Sold loop ?>

通了——

我在第一个循环的数组中"排除"了类别 ID 以将其删除,因此在第二个循环中,我"包含"了相同的类别 ID。 太简单了...我虽然它会包括该 ID 以及其他 ID,但认为它是多余的。无论如何,感谢您的帮助!

<?php   
$args = array(
'include'   => '367'
);
$categories = get_categories( $args );
$parent_categories = '';
foreach ( $categories as $category ) { ?>

最新更新