使用带有“更多"字样的 Wordpress 摘录关联? [英] Use Wordpress' Excerpt with a "more" link?

查看:27
本文介绍了使用带有“更多"字样的 Wordpress 摘录关联?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Wordpress 的文档建议将以下内容添加到 functions.php 以启用我想要执行的操作:

Wordpress' documentation suggests adding the following to functions.php to enable what I want to do:

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

根据:http://codex.wordpress.org/Function_Reference/the_excerpt

但是当我将它添加到functions.php,并尝试使用它时,我没有看到更多链接.这是我尝试使用它的方法:

But when I add this to functions.php, and I attempt to use it, I don't see the more link. Here is how I try to use it:

the_excerpt(__('(more...)'));

我也试过:

the_excerpt();

<小时>

更新:我尝试了以下操作,但它要么返回错误(如果没有参数),要么不显示任何摘录或任何内容(如果有参数):


Update: I've tried the following, but it either returns an error (if no arguments), or it doesn't display any excerpt or anything (if an argument):

function new_excerpt_more($excerpt) {
    $link = get_permalink();
    $title = the_title('','',false);
    $ahref = '<a href="'.$link.'" title="'.$title.'">more...</a>';
    return str_replace('[...]', $ahref, $excerpt);
}
add_filter('wp_trim_excerpt', 'new_excerpt_more');

推荐答案

function new_excerpt_more($output) {
    return $output . '<p><a href="'. get_permalink() . '">' . 'Read the Rest...' . '</a></p>';
}
add_filter('get_the_excerpt', 'new_excerpt_more');

适用于:

<?php the_excerpt(); ?>

这篇关于使用带有“更多"字样的 Wordpress 摘录关联?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆