我对PHP非常陌生,真的不知道从哪里开始编写它。Wordpress:将函数内部的链接添加到函数中
我发现这个功能的WordPress我使用其中:
function excerpt($limit) {
$excerpt = explode(' ', get_the_excerpt(), $limit);
if (count($excerpt)>=$limit) {
array_pop($excerpt);
$excerpt = implode(" ",$excerpt).'<a href="<?php the_permalink(); ?>">Read In Full</a>';
} else {
$excerpt = implode(" ",$excerpt);
}
$excerpt = preg_replace('`\[[^\]]*\]`','',$excerpt);
return $excerpt;
}
function content($limit) {
$content = explode(' ', get_the_content(), $limit);
if (count($content)>=$limit) {
array_pop($content);
$content = implode(" ",$content).'[...]';
} else {
$content = implode(" ",$content);
}
$content = preg_replace('/\[.+\]/','', $content);
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]>', $content);
return $content;
}
在上面的代码中,我放置
"<?php the_permalink(); ?>"
到HREF。它只是显示为一串文字,而不是创建对帖子链接的调用。
有人帮我解决吗? 谢谢!
你叫这里面的“循环”? http://codex.wordpress.org/The_Loop –
是的,这里是代码: '<?php $ firmnews = new WP_Query(); \t \t \t \t \t $ firmnews-> query('showposts = 2'); ($ firmnews-> have_posts()):$ firmnews-> the_post(); ?>
摘录中的“Read In Full”链接,尝试用'get_permalink()'替换'the_permalink()'。 the_permalink()回显链接,而get_permalink()将返回链接。在你的情况下,你正在追加链接,所以第二个是首选 – sbrajesh