【问题标题】:Display a Post Excerpt in Sidebar?在侧边栏中显示帖子摘录?
【发布时间】:2011-12-26 05:01:44
【问题描述】:

我正在重新设计我的网站,发现自己需要在我的侧边栏上显示帖子摘录。 the_excerpt() 似乎是正确的使用方法,但我也在我的主博客页面上使用摘录。 55 个字的限制在我的主页上看起来不错,但不是我的侧边栏。我需要一种方法来限制仅在我的侧边栏中的 the_excerpt 中返回的单词。

<div id="sidebar">
    <a href="<?php the_permalink(); ?>" title="Permalink to <?php the_title(); ?>">
        <?php the_title() ?> 
    </a>
    <?php the_excerpt(); ?>
</div>

我希望在侧边栏中,摘录长度限制在 20 个字以内

【问题讨论】:

标签: php wordpress themes


【解决方案1】:

你可以使用 substr()

<div id="sidebar">
    <a href="<?php the_permalink(); ?>" title="Permalink to <?php the_title(); ?>">
        <?php the_title() ?> 
    </a>
    <?php $mycontent=get_the_excerpt(); 
      echo substr($mycontent,0,20);
    ?>
</div>

【讨论】:

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