【问题标题】:Modify php for 'read more' text to link to a specific WordPress page修改“阅读更多”文本的 php 以链接到特定的 WordPress 页面
【发布时间】:2017-03-13 04:18:37
【问题描述】:

我正在尝试修改 WordPress 插件中的“阅读更多”以链接到特定页面,而不是默认等效的帖子。在这种情况下,它是推荐插件的一部分。

我找到了将以下代码添加到主题 functions.php 文件末尾并修改 $more_text 变量的说明,但我不确定应该在哪里添加页面 id 或 url 以及是否应该替换任何现有的sn-p。这是代码——

function hg_testimonial_rotator_the_excerpt( $html, $limit )
{
    $more_text = '... <a class="read-more"    href="'.get_permalink(get_the_ID()).'">Read the Rest...</a>';
    return wp_trim_words(get_the_excerpt(), $limit, $more_text);
}
add_filter('testimonial_rotator_the_excerpt',    'hg_testimonial_rotator_the_excerpt', 10, 2);

有什么建议吗?

【问题讨论】:

    标签: php wordpress variable-assignment


    【解决方案1】:

    您可以在 a href 中放置新链接。

    $more_text = '... <a class="read-more" href="here goes your new link">Read the Rest...</a>';
    

    您可以添加静态链接,例如:

    $more_text = '... <a class="read-more" href="http://www.stackoverflow.com/">Read the Rest...</a>';
    

    或者你可以像你的例子一样生成一个链接。

    【讨论】:

    • 谢谢,这正是我所需要的。
    猜你喜欢
    • 2012-11-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-29
    • 1970-01-01
    • 2015-02-04
    • 1970-01-01
    • 1970-01-01
    • 2013-03-29
    相关资源
    最近更新 更多