限制wordpress中多个<p>标签中的文本</p>

时间:2014-08-24 17:24:29

标签: jquery html wordpress tags

我正在写一篇博客,并希望用&#34; ...&#34;来限制文字。但在管理员帖子页面,它不允许
标签只有P标签分开段落。我的观点我想限制我的文字,即使有10个P标签。用户可以访问该页面并查看完整的帖子,但在登录页面上,它只显示有限的文字。

请帮忙。

1 个答案:

答案 0 :(得分:0)

嗯,你可以使用很多方法。其中一个显然是使用the_excerpt();在你的模板中。如果你想在摘录中添加更多字符(默认值除外) 在你的functions.php文件中尝试这段代码

function new_excerpt_length($length) {
    return 50;
}
add_filter('excerpt_length', 'new_excerpt_length');

function the_titlesmall($before = '', $after = '', $echo = true, $length = false) { $title = get_the_title();

    if ( $length && is_numeric($length) ) {
        $title = substr( $title, 0, $length );
    }

    if ( strlen($title)> 0 ) {
        $title = apply_filters('the_titlesmall', $before . $title . $after, $before, $after);
        if ( $echo )
            echo $title;
        else
            return $title;
    }
}

只需将return 50更改为您想要的任何长度

替代方法:在模板中使用content()函数,在functions.php页面中使用:

function content($limit) {
  $content = explode(' ', get_the_content(), $limit);
  if (count($content)>=$limit) {
    array_pop($content);
    $content = implode(" ",$content).' <a class="seemore" href="'. get_permalink($post->ID) . '">More</a>';
  } else {
    $content = implode(" ",$content);
  } 
  $content = preg_replace('/\[.+\]/','', $content);
  $content = apply_filters('the_content', $content); 
  $content = str_replace(']]>', ']]&gt;', $content);
  return $content;
}

现在您可以在模板中使用<?php echo content(50); ?>(或以您想要的任意长度替换50)

最后,您还可以在帖子/页面编辑屏幕中使用MORE标记