Question
を使用して問題がある、以下:
ので !私はいくつかのページ (残念ながら) ページ上のスタイルを持っていると少しテキスト、抜粋制限は何が起こっているので、15 文字を満たしていないが達成されていない、それが表示されますので ‘ 少しのテキスト.その後
、等 ‘.
どのように書き換えることができます私は最大 15 文字の制限、または最大。だからそれが足りない場合は結構です。HTML を除外する、または/および CSS?
functions.php 内の関数の抜粋
function excerpt($limit) {
$excerpt = explode(' ', get_the_excerpt(), $limit);
if (count($excerpt)>=$limit) {
array_pop($excerpt);
$excerpt = implode(" ",$excerpt).'...';
} else {
$excerpt = implode(" ",$excerpt);
}
$excerpt = preg_replace('`\[[^\]]*\]`','',$excerpt);
return $excerpt;
}
function content($limit) {
$content = explode(' ', get_the_content(), $limit);
if (count($content)>=$limit) {
array_pop($content);
$content = implode(" ",$content).'...';
} else {
$content = implode(" ",$content);
}
$content = preg_replace('/\[.+\]/','', $content);
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]>', $content);
return $content;
}
remove_filter('get_the_excerpt', 'wp_trim_excerpt');
add_filter('get_the_excerpt', 'custom_trim_excerpt');
function custom_trim_excerpt($text) { // Fakes an excerpt if needed
global $post;
if ( '' == $text ) {
$text = get_the_content('');
$text = apply_filters('the_content', $text);
$text = str_replace(']]>', ']]>', $text);
$text = strip_tags($text);
$excerpt_length = 35;
$words = explode(' ', $text, $excerpt_length + 1);
if (count($words) > $excerpt_length) {
array_pop($words);
array_push($words, '...');
$text = implode(' ', $words);
}
}
return $text;
}
答え
-
(おそらくより、これはすべてを網羅するものではありません) の 3 つのオプションがある
ワードプレスの機能を放棄します。カスタムの PHP を使用して渡す、$post -> post_content を通じて、独自の関数をことができる関数を使用する PHP の XML 操作、特に DOM 操作、または正規表現は、特定のタグを削除する
-
抜粋を実行する前に記事の内容のチェックを行います。最初の位置を確認して、最初の 15 文字内の開始タグの存在を確認することができる場合、「<」を使用してできます通常の場合/他 strpos、を使用して文字。
- 正しく wordpresses 機能を使用して、フィルターを通して、抜粋対処方法を変更できます。既定の機能を削除してあなた自身でそれを置換できます。 このリンク は特には、ワードプレスでは、タグを許可するに関して具体的または抜粋内ではなく、抜粋関数をカスタマイズする方法を説明する便利です
。
。
http://stackoverflow.com/questions/27574281/php-max-excerpt-length-not-must-length-exclude-html-css