【问题标题】:how to implement read more button in every post of wordpress如何在wordpress的每篇文章中实现阅读更多按钮
【发布时间】:2012-02-02 20:38:57
【问题描述】:

我正在网站上工作http://www.nickthepromisering.com/

现在朋友们,我的问题是如何通过添加阅读更多按钮来限制 wordpress 帖子中的字数。 以便只显示一些字词,然后当点击阅读更多按钮显示剩余的帖子。我的意思是有任何插件吗?

【问题讨论】:

  • the_content 在主题文件夹中的什么位置?
  • 为什么不直接使用编辑器中的“更多”按钮?还是必须自动工作?
  • 这必须自动工作

标签: php wordpress


【解决方案1】:

要仅显示帖子的一部分内容,请将主题中的 the_content(); 更改为 the_excerpt();

然后,添加阅读更多链接,如下所示:<a href="<?php the_permalink(); ?>">Read more</a>

【讨论】:

  • the_content 在主题文件夹中的什么位置?
  • 它将位于多个位置,具体取决于您的主题。检查index.phparchive.phpcategory.php 确定。在您的文本编辑器中进行全站搜索,您可能希望在除page.phpsingle.php 之外的所有位置替换the_content();
【解决方案2】:
echo implode (" ", array_slice (explode (" ", strip_tags($post->post_content)), 300));
echo '<a href="' .the_permalink() .'">Read more</a>';

请注意,这也会删除 HTML,否则您可能会得到半开标签..

【讨论】:

    猜你喜欢
    • 2022-09-29
    • 1970-01-01
    • 2017-09-30
    • 1970-01-01
    • 2021-08-22
    • 2021-12-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多