我有wordpress网站,我想收到最近的帖子。所以我使用循环
<?php $args = array( 'numberposts' => '3' );
$recent_posts = wp_get_recent_posts($args);?>
<ul>
<?php foreach( $recent_posts as $recent ){?>
<li>
<?php echo '<div class="textoverlay">
<a href="' . get_permalink($recent["ID"]) . '"><h1>' . $recent["post_title"].'</h1></a>
<p>'.get_post_field('post_content', $recent["ID"]).'</p>
</div> ';
if ( has_post_thumbnail($recent["ID"]) ) {
echo get_the_post_thumbnail($recent["ID"],'thumbnail');
} ?>
</li>
<?php
}?>
</ul>
我使用get_post_field进行帖子描述,但我看到了完整的描述。那么有可能通过ID获得帖子的简短描述吗?例如,前10个单词?
答案 0 :(得分:0)
$content = get_post_field('post_content', $recent["ID"]);
$content = strip_tags($content);
echo substr($content, 0, 10);
只需使用substr作为前10个单词