wordpress - 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;
?>
解决方案
试试这个脚本:
<?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;
?>
回复:
推荐阅读
- nearley - 如何将回车添加到近乎可能的空白值?
- python - 如何使用 plotly express 在地图框中绘制线串的 GeoJSON 特征集合?
- apiblueprint - 养蜂场身份验证描述不起作用?
- node.js - 如何返回子文档的计数数组猫鼬
- python - 使用 python api ibm_db 连接到 IBM DB2 on Cloud
- python - 由于尺寸不同,如何将 ndarray 转换为 EagerTensor?
- keycloak - 生成 Keycloak 离线令牌
- android - 如何仅在进行 http 调用后启用导航单击?
- android - 如何从 NativeScript 应用程序捕获来自 Android WebView / WebViewClient 的事件?
- wix - 如何为wix velo corvid中的所有成员动态实现堆识别和addUserProperties