如何计算帖子中的字数?就像在柱子下面显示的一样?
谁能给我看看这个的代码吗。我到处都在找。
如何计算帖子中的字数?就像在柱子下面显示的一样?
谁能给我看看这个的代码吗。我到处都在找。
你搜索得有多努力?我在Google上搜索了“wordpress count words in post”,并在第一个结果中找到了一个函数!
把这个放进去functions.php
:
function prefix_wcount(){
ob_start();
the_content();
$content = ob_get_clean();
return sizeof(explode(" ", $content));
}
然后在模板中调用它,如下所示:<?php echo prefix_wcount(); ?>
只需计算空格并添加1:
// No need to count markup.
$text = trim( strip_tags( get_the_content() ) );
$word_number = substr_count( "$text ", \' \' );
另一种方式,考虑到古老的美国双空间传统:$word_number = preg_match_all( \'~\\s+~\', "$text ", $m );
简单明了的方法。
$word_count = str_word_count(trim(strip_tags($post->post_content)));
我需要显示作者图片和帖子。我使用以下代码显示带有作者图像的帖子。$the_query = new WP_Query(\"post_type=post&paged=\".get_query_var(\'paged\')); while ( $the_query->have_posts() ) : $the_query->the_post(); <?php the_excerpt(); ?> <p><?php the_auth