【问题标题】:Trying to add a featured post with thumbnail to home page not sidebar尝试将带有缩略图的精选帖子添加到主页而不是侧边栏
【发布时间】:2011-05-10 00:12:43
【问题描述】:

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

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

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

【问题讨论】:

    标签: wordpress


    【解决方案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; ?>
    

    【讨论】:

      猜你喜欢
      • 2019-04-15
      • 1970-01-01
      • 2011-04-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-06
      相关资源
      最近更新 更多