在变量中混合使用PHP和HTML

时间:2011-03-30 10:13:06

标签: php html wordpress

我正在尝试创建一个Wordpress插件,在所有帖子下面添加一个按钮。该按钮是一个“赞”按钮,通过URL将一些参数传递给新站点。

参数是Wordpress永久链接,标题和博客名称。

无法使其发挥作用。

function add_bloglovin($content) {

   $blog_title = get_bloginfo('name');
   $link = the_permalink();
   $title = the_title();

   $bloglovin ="<br><a href=\"http://www.bloglovin.com/like/?b=$blog_title&p=$link&t=$title\" onclick=\"window.open(this.href, 'bloglovin_like', 'width=480,height=320, toolbar=0, location=0, menubar=0, scrollbars=0, status=0'); return false;\"><img src=\"http://www.bloglovin.com/widget/bilder/like.gif\"></a>";
   return $content .$bloglovin;
}
add_filter('the_content', add_bloglovin);

3 个答案:

答案 0 :(得分:3)

the_permalink()是一个显示功能。使用get_permalink()返回可以使用的字符串。要使the_title只返回没有包装HTML的标题,你需要使用the_title('','',false);

function add_bloglovin($content) {
    $blog_title = get_bloginfo('name');
    $link = get_permalink();
    $title = the_title('','',false);
    $bloglovin ="<br><a href=\"http://www.bloglovin.com/like/?b=$blog_title&p=$link&t=$title\" onclick=\"window.open(this.href, 'bloglovin_like', 'width=480,height=320, toolbar=0, location=0, menubar=0, scrollbars=0, status=0'); return false;\"><img src=\"http://www.bloglovin.com/widget/bilder/like.gif\"></a>";
    return $content .$bloglovin;
}

答案 1 :(得分:1)

来自Wordpress Codex: http://codex.wordpress.org/Function_Reference/the_permalink

功能参考/永久链接

  

显示固定链接的URL   目前正在处理的帖子   循环。此标记必须在The。中   循环,通常用于显示   每个帖子的永久链接,当   正在显示帖子。从此   模板标签仅限于显示   这个职位的永久链接   正在处理,你不能使用它   显示永久链接   发布在你的博客上。

你不能使用$ link = the_permalink();孤立的,除非它在the Loop

答案 2 :(得分:0)

通过var_dump() $link$title变量尝试进行基本的健全性检查。它们实际上是否包含字符串?

相关问题