私はブログの投稿にこのカスタム抜粋を追加しようとしているので、投稿から最初の35文字を取得し、その抜粋を作成します。しかし、このコードはすべてのPost Types、カスタムPostタイプでも機能します。ブログの投稿のWordpressのカスタム抜粋
このカスタム抜粋のみをブログ投稿にのみ適用するにはどうすればよいですか?私は以下の条件で、以下のコードをラップしようとしました - これはデフォルトのブログ投稿ページが設定されていますが、動作しませんでした。
if ($post->post_type !== 'post') {
return $content;
}
global $post
行の後に次の行を追加します。
if(is_page_template('template-blog-list.php')) {
function custom_excerpts($content = false) {
global $post;
$content = wp_strip_all_tags($post->post_content);
$excerpt_length = 35;
$words = explode(' ', $content, $excerpt_length + 1);
if(count($words) > $excerpt_length) :
array_pop($words);
array_push($words, '...');
$content = implode(' ', $words);
endif;
$content = $content . '<br><br><a class="more-button" href="'. get_permalink($post->ID) . '">Read More</a>';
return $content;
}
add_filter('get_the_excerpt', 'custom_excerpts');
}
非常に素晴らしい戻る - 短いと甘いです。ありがとう。 – optimus203