简体   繁体   English

WordPress-获得近期帖子的简短描述

[英]Wordpress - get short description of recent post

I have wordpress website and I want to get recent posts. 我有wordpress网站,我想获得最近的帖子。 So I use loop 所以我用循环

<?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>

I use get_post_field for post description, but I see full description. 我将get_post_field用于帖子描述,但是我看到了完整的描述。 So is it possible to get short description of post by ID ? 那么是否有可能通过ID获得帖子的简短描述? For example first 10 words ? 例如前10个字?

$content = get_post_field('post_content', $recent["ID"]);
$content = strip_tags($content);
echo substr($content, 0, 10);

just use substr for first 10 words 只需对前10个单词使用substr

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM