【发布时间】:2018-07-28 07:42:48
【问题描述】:
我正在尝试用较大的封面图片和摘录突出显示主页中的三个最新帖子,这样如果它们被突出显示,它们就不会出现在较小的帖子列表中。像这样,但最近的帖子在上面:
我尝试过使用多个带有偏移量的 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;
?>
【问题讨论】:
-
把你试过的代码放在这里?
-
添加了@GufranHasan!
-
我认为你应该把
wp_reset_postdata()放在while循环结束之后 -
@GufranHasan 完成,但我仍然得到未定义的偏移错误。
-
我回答了,试试那个。
标签: wordpress