如何从最近的文章的侧边栏列表中排除类别


How to Exclude Categories from Sidebar listing of Recent Posts in Wordpress?

我试图从侧栏中列出的最近的帖子中排除几个类别。这是我得到的,但它不起作用($ex部分是我试图排除的地方)。欢迎提出任何建议:

<?php
        $latest = get_posts('numberposts=7');
        $i = 0;
        $ex = "65,86";
        ?>
        <?php foreach ($latest as $latest_post): $i++; ?>
            <li <?php if ($i === 1) echo 'id="most_recent"' ?>><a href="<?php echo get_permalink($latest_post->ID) ?>"><?php echo $latest_post->post_title ?></a></li>
        <?php endforeach ?>
    </ul>
</div>

我可能会为此使用自定义循环。下面的代码应该可以工作:

<!--Set up your query here.  In this example we're excluding cats 1, 2, 3 and displaying 5 posts-->
<?php query_posts( 'cat=-1,-2,-3&posts_per_page=5' ); ?>        
<!--Start the loop-->       
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<!--Your HTML and template tags here-->
<li><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a></li>
<?php endwhile; ?>
<?php else: ?>
<!-- Put something here in case there are not recent posts-->
<?php endif; wp_reset_query();?>
<!--Make sure you include the reset query function at the end here if you want other custom loops after this one-->

使用查询文章的好处是,你可以使用wordpress

中可用的所有其他参数参数

http://codex.wordpress.org/Function_Reference/query_posts