精选 post 循环显示错误的 post 摘录
Featured post loop displaying wrong post excerpt
我正在处理 WordPress 主题问题,我有一个存档页面,顶部有特色 post,显示特色图片、post 日期和摘录以及其他 post在它下面。
运行 遇到一个问题,其中精选 post 的标题、图片正确,但摘录不正确。它会引入不同的 post 文本。
关于以下代码不正确之处的任何线索?
<?php
$args = array(
'numberposts' => '1' ,
'post_type' => 'post',
'meta_key' => 'post_featured',
'meta_compare' => '=',
'meta_value' => 1
);
$recent_posts = wp_get_recent_posts( $args );
$fID = 0;
foreach( $recent_posts as $recent ) : ?>
<?php $fID = $recent["ID"]; ?>
<div class="blog-listing featured_post">
<a class="blog-image-lg" href="<?php echo get_permalink($recent["ID"]); ?>" style="background-image: url('<?php echo get_the_post_thumbnail_url( $recent["ID"], 'full' ); ?>');">
<span>FEATURED POST</span>
<?php echo get_the_post_thumbnail( $recent["ID"], 'post-thumbnails-big' ); ?>
</a>
<div class="blog-info pull-left">
<a href="<?php echo get_permalink($recent["ID"]); ?>"><h3 class="blog-title"><?php echo $recent["post_title"]; ?></h3></a>
<span class="blog-date"><?php echo strtoupper(get_the_date('F j, Y')); ?></span>
<p><? echo the_excerpt(); ?></p>
<p class="readmore-wrapper"><a class="readmore" href="<?php echo get_permalink($recent["ID"]); ?>">READ MORE »</a></p>
</div>
</div>
将 <? echo the_excerpt(); ?>
更改为 <?php echo get_the_excerpt($recent["ID"]); ?>
。
the_excerpt()
在您的情况下不起作用,因为您不在 WP 循环内,只是一个常规的 for 循环。
我正在处理 WordPress 主题问题,我有一个存档页面,顶部有特色 post,显示特色图片、post 日期和摘录以及其他 post在它下面。
运行 遇到一个问题,其中精选 post 的标题、图片正确,但摘录不正确。它会引入不同的 post 文本。
关于以下代码不正确之处的任何线索?
<?php
$args = array(
'numberposts' => '1' ,
'post_type' => 'post',
'meta_key' => 'post_featured',
'meta_compare' => '=',
'meta_value' => 1
);
$recent_posts = wp_get_recent_posts( $args );
$fID = 0;
foreach( $recent_posts as $recent ) : ?>
<?php $fID = $recent["ID"]; ?>
<div class="blog-listing featured_post">
<a class="blog-image-lg" href="<?php echo get_permalink($recent["ID"]); ?>" style="background-image: url('<?php echo get_the_post_thumbnail_url( $recent["ID"], 'full' ); ?>');">
<span>FEATURED POST</span>
<?php echo get_the_post_thumbnail( $recent["ID"], 'post-thumbnails-big' ); ?>
</a>
<div class="blog-info pull-left">
<a href="<?php echo get_permalink($recent["ID"]); ?>"><h3 class="blog-title"><?php echo $recent["post_title"]; ?></h3></a>
<span class="blog-date"><?php echo strtoupper(get_the_date('F j, Y')); ?></span>
<p><? echo the_excerpt(); ?></p>
<p class="readmore-wrapper"><a class="readmore" href="<?php echo get_permalink($recent["ID"]); ?>">READ MORE »</a></p>
</div>
</div>
将 <? echo the_excerpt(); ?>
更改为 <?php echo get_the_excerpt($recent["ID"]); ?>
。
the_excerpt()
在您的情况下不起作用,因为您不在 WP 循环内,只是一个常规的 for 循环。