尝试将带有缩略图的精选帖子添加到主页而不是侧边栏



我目前正在尝试在我的wordpress主页上添加一个特色帖子,该帖子将链接到博客中的帖子。

我在下面找到了插件,但它只将其添加到侧边栏,有谁知道一个插件可以做类似的事情但可以放在主页上

http://wordpress.org/extend/plugins/featured-post-with-thumbnail/

你真的不需要插件。 执行此操作的一种快速方法是创建一个主页.php模板文件,然后将"精选"类别的第一篇文章拉入主页模板中:

<?php
query_posts(array('category_name' => 'featured', 'posts_per_page' => '1'));
if(have_posts()): the_post(); 
$do_not_duplicate = $post->ID; // set up the post so you can skip it later
$thumbnail = get_the_post_thumbnail($post->ID, 'medium');?>
<div id="post-<?php the_ID(); ?> <?php post_class(); ?>>
    <?php the_content(); // the post content ?>
    <?php echo $thumbnail; // the Featured image set with the post ?>
</div>
<?php endwhile; endif; wp_reset_query(); ?>
<?php // set up the query for the rest of your posts
 if(have_posts()) : while(have_posts()): the_post();
 if($post->ID == $do_not_duplicate) continue; // skip the one that's already showing ?>
 <!-- do your layout here -->
<?php endwhile; endif; ?>

最新更新