WordPressサイト内に2つのカテゴリを作成し、それぞれのカテゴリに1つの投稿を作成しました。私は別のページに各カテゴリーの投稿から抜粋しています。WordPress 2段落を表示する抜粋
私は、各ページにそのように抜粋を表示しており、手動でさらにリンクを読むことを追加しています。
<?php query_posts('cat=4&showposts=1'); ?>
<?php while (have_posts()) : the_post(); ?>
<h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
<?php the_excerpt(); ?>
<a href="<?php the_permalink(); ?>">Read More</a>
<?php endwhile; ?>
次のコードは、最初の段落の後の抜粋を終了します。私がやりたい何
function post_single_paragrapgh($text, $raw_excerpt) {
if(! $raw_excerpt) {
$content = apply_filters('the_content', get_the_content());
$text = substr($content, 0, strpos($content, '</p>') + 4);
}
return $text;
}
add_filter('wp_trim_excerpt', 'post_single_paragrapgh', 10, 2);
は、第二段落や、実際に画像や段落の後に遮断することを教えています。
投稿の先頭に1つがある場合は画像をプルしますが、画像の後ろに段落を追加するか、テキストの2段落も追加します。どちらかまたは。
私はこのサイトを参考にしましたが、方法C1はエラーをスローします。 https://www.bybe.net/wordpress-the_excerpt-show-first-paragraph/
ありがとうございます!
[質問に関するstrposの可能な重複。どのように文字列の2番目の発生を取得するには?](http://stackoverflow.com/questions/3126324/question-about-strpos-how-to-get-2nd-occurrence-of-the-string) – rnevius