首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在函数php中将字符输出限制为12个单词

在函数php中将字符输出限制为12个单词
EN

Stack Overflow用户
提问于 2014-08-28 19:59:45
回答 1查看 161关注 0票数 0

再次需要一点帮助,这是一个返回文本内容并在wordpress中阅读更多链接的函数:

代码语言:javascript
复制
function whisper_entry_contentoffer1()
{
global $whisper;

// Check on singular pages
$is_single = is_singular() && !is_page_template( 'tpl/blog.php' ) && !is_page_template( 'tpl/blog-boxes.php' );

// Allow to config via global variable
if ( isset( $whisper['is_single'] ) )
    $is_single = $whisper['is_single'];

if ( $is_single )
{
    echo '<div class="entry-content">';
    the_content();
    wp_link_pages( array(
        'before'      => '<p class="pages">' . __( 'Pages:', 'whisper' ),
        'after'       => '</p>',
        'link_before' => '<span>',
        'link_after'  => '</span>',
    ) );
    echo '</div>';
    return;
}

// Archives & Blog pages

// Display type
$display = fitwp_option( 'blog_display' );

// Allow to config via global variable
if ( isset( $whisper['blog_display'] ) )
    $display = $whisper['blog_display'];

if ( !$display )
    $display = 'content';

echo '<div class="entry-summary">';

// Excerpt
if ( 'excerpt' == $display )
{
    the_excerpt();
    return;
}

$more_text = whisper_more_text2();

// Post content before more tag
if ( 'more' == $display )
{
    if ( is_page_template( 'tpl/blog.php' ) || is_page_template( 'tpl/blog-boxes.php' ) )
    {
        global $more;
        $more = false;
    }

    the_content( $more_text );
    wp_link_pages( array(
        'before'      => '<p class="pages">' . __( 'Pages:', 'whisper' ),
        'after'       => '</p>',
        'link_before' => '<span>',
        'link_after'  => '</span>',
    ) );
}
else
{
    whisper_content_limitoffer1( whisper_content_length(), $more_text );
}

echo '</div>'; // .entry-summary
}

现在我需要将输出文本限制为12个单词。有什么建议或建议吗?!

谢谢..。

EN

回答 1

Stack Overflow用户

发布于 2014-08-28 20:08:09

这?将$string替换为您的字符串

代码语言:javascript
复制
echo implode(" ",array_splice(explode(" ",$string),0,20));
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25548275

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档