私のループを動作していないカウント、次のようになりますWordPressの抜粋文字が
<!-- loop for the posts here -->
<?php
$args = array(
'post_type' => 'post',
'posts_per_page' => 3,
'category_name' => 'news'
);
$query = new WP_Query($args);
while($query->have_posts()) : $query->the_post();
?>
<div class="news_box_content">
<h5><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h5>
<figure><a href="<?php the_permalink(); ?>"><?php the_post_thumbnail(); ?></a></figure>
<?php if($post->post_excerpt) { ?>
<p><?php echo get_the_excerpt(); ?></p>
<a href="<?php the_permalink(); ?>">Read more...</a>
<?php } else {
the_content('Read More');
} ?>
</div>
<?php endwhile; wp_reset_postdata(); ?>
私が抜粋長をカウントする機能を使用しますが、それは動作しません。
function custom_excerpt_length(){
return 10;
}
add_filter('excerpt_length', 'custom_excerpt_length');
どのように抜粋の文字数を制限できますか?
あなたのカスタム抜粋関数、つまりcustom_excerpt_length()を呼び出す必要があります。 get_the_excerpt()の代わりに。 – Samyappa
あなたは正しいですよ。 –