您可以创建自己的小部件,查询特定类别的帖子,然后显示the_post_thumbnail
在链接到帖子的无序列表中。
示例小部件(添加到functions.php):
<?php
class c3m_thumbnail_posts extends WP_Widget {
function c3m_thumbnail_posts() {
$widget_ops = array( \'classname\' => \'thumbnail-posts\', \'description\' => \'Displays post thumbnails\' );
$control_ops = array( \'id_base\' => \'c3m-post-thumbnail\' );
$this->WP_Widget( \'c3m-post-thumbnail\', \'Post Thumbnail Widget\', $widget_ops, $control_ops );
}
function widget( $instance ) {
echo $before_widget;
?>
<h2>Title Goes Here</h2>
<?php
$args = array(
\'cat\' => 16, //Replace with category ID of posts to show thumbnail for
\'posts_per_page\' => 6 //Replace with number of posts to show use -1 for all
);
$thumbnail_query = new WP_Query( $args ); ?>
<ul class="sidebar-thumbnails">
<?php
while ( $thumbnail_query->have_posts() ) : $thumbnail_query->the_post(); ?>
<li><a href="<?php the_permalink(); ?>"><?php the_post_thumbnail(); ?></a></li>
<?php endwhile; ?>
</ul>
<?php
echo $after_widget;
}
}
要修改使用的帖子,请参见
WP_Query class 在法典中。