我已经编写了一个函数来替换WordPress的默认“Read More”链接以获取我自己的帖子摘录,但是现在我试图用特定页面上略有不同的HTML属性替换它,但是我得到语法错误。
功能:
function new_excerpt_more($more) {
global $post;
if (is_page( '39' )) {
return ' […]<p><a class="moretag btn btn-primary btn-xl wow bounceIn" href="'. get_permalink($post->ID) . '">Continue reading <span aria-hidden="true">→</span></a></p>';
}
} else {
return ' […]<p><a class="moretag btn btn-primary btn-md" href="'. get_permalink($post->ID) . '">Continue reading <span aria-hidden="true">→</span></a></p>';
}
}
add_filter('excerpt_more', 'new_excerpt_more');
错误:
Parse error: syntax error, unexpected 'else' (T_ELSE) in /home/ourcore/public_html/wp-content/themes/portfolio/functions.php on line 7
任何帮助都会非常感激。提前谢谢!
答案 0 :(得分:2)
你有一个太多的结束大括号
function new_excerpt_more($more) {
global $post;
if (is_page( '39' )) {
return ' […]<p><a class="moretag btn btn-primary btn-xl wow bounceIn" href="'. get_permalink($post->ID) . '">Continue reading <span aria-hidden="true">→</span></a></p>';
}
else {
return ' […]<p><a class="moretag btn btn-primary btn-md" href="'. get_permalink($post->ID) . '">Continue reading <span aria-hidden="true">→</span></a></p>';
}
}
add_filter('excerpt_more', 'new_excerpt_more');