首页 文章

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

提问于
浏览
0

我目前正在尝试添加一个精选帖子到我的wordpress主页,该主页将链接到博客中的帖子 .

我在下面找到了插件,但它只将它添加到侧栏,有没有人知道插件做了类似但可以放在主页上的插件

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

1 回答

  • 1

    你真的不需要一个插件 . 一个快速的方法是创建一个home.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; ?>
    

相关问题