有条件地取代帖子摘录“阅读更多”链接

时间:2016-06-02 05:19:47

标签: php wordpress

我已经编写了一个函数来替换WordPress的默认“Read More”链接以获取我自己的帖子摘录,但是现在我试图用特定页面上略有不同的HTML属性替换它,但是我得到语法错误。

功能:

function new_excerpt_more($more) {
  global $post;
    if (is_page( '39' )) {
        return ' [&#8230;]<p><a class="moretag btn btn-primary btn-xl wow bounceIn" href="'. get_permalink($post->ID) . '">Continue reading <span aria-hidden="true">&rarr;</span></a></p>';
        }
    } else {
        return ' [&#8230;]<p><a class="moretag btn btn-primary btn-md" href="'. get_permalink($post->ID) . '">Continue reading <span aria-hidden="true">&rarr;</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

任何帮助都会非常感激。提前谢谢!

1 个答案:

答案 0 :(得分:2)

你有一个太多的结束大括号

function new_excerpt_more($more) {
    global $post;
    if (is_page( '39' )) {
        return ' [&#8230;]<p><a class="moretag btn btn-primary btn-xl wow bounceIn" href="'. get_permalink($post->ID) . '">Continue reading <span aria-hidden="true">&rarr;</span></a></p>';
    }
     else {
        return ' [&#8230;]<p><a class="moretag btn btn-primary btn-md" href="'. get_permalink($post->ID) . '">Continue reading <span aria-hidden="true">&rarr;</span></a></p>';
    }
}
add_filter('excerpt_more', 'new_excerpt_more');