【问题标题】:the_excerpt only on last postthe_excerpt 仅在最后一篇文章中
【发布时间】:2015-08-13 07:54:25
【问题描述】:

所以我有问题,我无法解决。我想获得诸如标题和摘录之类的帖子数据。但是当我使用我的代码时,它只显示最后一篇文章的摘录,其他所有内容都有正常内容。所以我希望所有帖子都有摘录。

<div class="postai">
<div class="postu_pavadinimas"></div>

<ul>
<?php
$args = array( 'posts_per_page' => 6 );
$lastposts = get_posts( $args );
foreach ( $lastposts as $post ) : setup_postdata( $post ); ?>
    <li>
        <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
        <?php the_excerpt();?>
    </li>
    <?php endforeach; 
    wp_reset_postdata(); ?>
</div>
</ul>

编辑: 好的 1 观察,当我将最大帖子更改为 3 时,我根本没有得到任何摘录,只有正常内容。当我更改为“posts_per_page”=> 8 时,第 6 和第 8 个帖子有摘录。我现在有点迷茫……

【问题讨论】:

  • 伙计们,我现在知道问题所在了。不知何故,我在帖子中的文字已损坏,摘录将其识别为一个符号。谢谢你的帮助:)

标签: php wordpress posts


【解决方案1】:

如果有效,请尝试使用get_the_excerpt。告诉我

<div class="postai">
<div class="postu_pavadinimas"></div>

<ul>
<?php
$args = array( 'posts_per_page' => 6 );
$lastposts = get_posts( $args );
foreach ( $lastposts as $post ) : setup_postdata( $post ); ?>
    <li>
        <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
      <?php echo apply_filters( 'the_excerpt', get_the_excerpt() ); ?>
    </li>
    <?php endforeach; 
    wp_reset_postdata(); ?>
</div>
</ul>

【讨论】:

  • 感谢回复,尝试了这个功能,但现在它只显示标题,没有来自帖子的数据。
  • 使用 echo 打印摘录
  • 显示所有帖子的内容,仅显示最后一个帖子的摘录
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-10-12
  • 2019-11-12
相关资源
最近更新 更多