0

私は検索ページで作業しており、そのページまたは投稿コンテンツから数行だけのデータを返したいと考えています。私はphpでこれを行うことができますが、ワードプレス側からの解決策を探しています. 私はそれを検索しましたが、満足のいく結果はありませんでした。

以下は、内容を表示するコードです

<div class="testimonial-content">
    <div class="thumb search_page_individual_contents">
        <?php the_content();?>
        <a href="<?php the_permalink(); ?>">

        </a>
    </div>
</div>

the_content() は、いずれかが見つかった場合にすべてのコンテンツを表示しますが、そのページまたは投稿の最初の 3 行のみを表示したいのです。

4

2 に答える 2

3

検索結果が表示される場所でこのコードを使用してください:

<?php the_excerpt(); ?>

そして、このコード行を function.php に追加します

function new_excerpt_more($more) {
       global $post;
    return '... <a href="'. get_permalink($post->ID) . '">Read more</a>';
}
add_filter('excerpt_more', 'new_excerpt_more');


function custom_excerpt_length( $length ) {
    return 20;
}
add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );
于 2013-09-09T07:05:29.810 に答える