首页 > 解决方案 > Wordpress 在首页突出显示最近的帖子

问题描述

我试图用较大的封面图片和摘录突出主页中的三个最新帖子,这样如果它们被突出显示,它们就不会出现在较小的帖子列表中。像这样的东西,但最近的帖子在上面:英国政府示例

我尝试过使用多个带有偏移量的 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;
?>

标签: wordpress

解决方案


试试这个脚本:

    <?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;               
 ?>

回复:

在此处输入图像描述


推荐阅读