WordPress在首页突出显示最近的帖子

时间:2018-07-28 07:42:48

标签: wordpress

我正尝试用较大的封面图像和摘录突出显示主页上的三个最新帖子,以便如果突出显示它们,则不会出现在较小的帖子列表中。这样的事情,但最新的帖子放在最前面:Gov.UK example

我已经尝试过使用多个带有偏移量的WP_Query,但是它似乎不太起作用(可能我做的不正确)。

有什么想法吗?谢谢!

编辑:这是我尝试过的。问题是我收到“未定义的偏移量”错误。

<?php
            /* Featured posts */
            ?>

            <div class="featured-posts columns">
                <?php
                $featured_query = new WP_Query( array( 'posts_per_page' => 3) );
                while ( $featured_query->have_posts() ) : the_post(); ?>
                    <div class="featured-post col-4">
                        <?php dge_post_thumbnail(); ?>
                        <div class="entry-meta">
                            <?php
                            dge_posted_on();
                            ?>
                        </div><!-- .entry-meta -->
                        <h2>
                            <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
                        </h2>
                        <p><?php the_excerpt(); ?></p>
                        <p><a href="<?php the_permalink(); ?>">continue reading</a></p>
                    </div>
                <?php endwhile; ?>
            </div>
<?php
            /* Start the Loop */
            $query = new WP_Query( array( 'posts_per_page' => 5, 'offset' => 3 ) );
            while ( $query->have_posts() ) :
                the_post();

                /*
                 * Include the Post-Type-specific template for the content.
                 * If you want to override this in a child theme, then include a file
                 * called content-___.php (where ___ is the Post Type name) and that will be used instead.
                 */
                /*get_template_part( 'template-parts/content', get_post_type() );*/
                get_template_part( 'template-parts/preview-content');

            endwhile;
?>

1 个答案:

答案 0 :(得分:0)

尝试以下脚本:

    <?php
       $featured_query = new WP_Query( array( 'posts_per_page' => 3,"orderby"=>"date","order"=>"DESC") );
        while ( $featured_query->have_posts() ) : $featured_query->the_post();
            echo '<p>'.the_title().'</p>';
        endwhile;               
  ?>
   <?php
        echo '<hr/><h1>After offset set</h1> <br/>';
        $featured_query = new WP_Query( array( 'posts_per_page' => 5,"orderby"=>"date","order"=>"DESC","offset"=>3) );
        while ( $featured_query->have_posts() ) : $featured_query->the_post();
            echo '<p>'.the_title().'</p>';
        endwhile;               
 ?>

响应:

enter image description here