【问题标题】:wordpress search results issueswordpress 搜索结果问题
【发布时间】:2013-09-09 18:09:06
【问题描述】:

我正在处理一个搜索页面,我想从该页面返回一个只有几行的数据或发布内容。我可以用 php 做到这一点,但我正在寻找 wordpress 方面的解决方案。我搜索了它,但没有满意的结果。

下面是显示内容的代码

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

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

如果有任何内容,the_content() 将显示所有内容,但我希望它只显示该页面或帖子的前三行。

【问题讨论】:

  • 7 次浏览后还没有评论,太奇怪了
  • 这是我第一次发生在 stackoverflow 上 10 次浏览和 9 分钟后我仍在等待回复
  • 我不知道我的问题是不是错了请告诉我
  • 这就是the_excerpt 函数的用途。检查codex.wordpress.org/Function_Reference/the_excerpt
  • 是的,这是解决方案,谢谢

标签: php wordpress


【解决方案1】:

你能在你的搜索结果显示的地方使用这个代码吗:

<?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 );

【讨论】:

    【解决方案2】:

    你也可以试试wp_trim_words()

    <?php
       echo wp_trim_words(the_content(), 40, 
                                '<a href="'. get_permalink() .'"> ...Read More</a>');
    ?>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多