【问题标题】:Featured post loop displaying wrong post excerpt精选帖子循环显示错误的帖子摘录
【发布时间】:2021-03-26 06:43:37
【问题描述】:

在处理 WordPress 主题问题时,我有一个存档页面,顶部有一个特色帖子,其中显示了特色图片、发布日期和摘录以及下面的其他帖子。

遇到了一个问题,其中精选帖子的标题正确,图片正确,但摘录不正确。它会引入不同的帖子文本。

关于下面的代码有什么不正确的任何线索吗?

<?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 &raquo;</a></p>
        </div>
    </div>   
                                

【问题讨论】:

    标签: php wordpress wordpress-theming


    【解决方案1】:

    &lt;? echo the_excerpt(); ?&gt; 更改为&lt;?php echo get_the_excerpt($recent["ID"]); ?&gt;

    the_excerpt() 在您的情况下不起作用,因为您不在 WP 循环中,而只是常规的 for 循环。

    【讨论】:

    • 完美,这解决了问题。谢谢!
    猜你喜欢
    • 2011-02-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-16
    • 2021-05-05
    • 1970-01-01
    • 2019-08-24
    • 1970-01-01
    相关资源
    最近更新 更多