我正试图在我博客上的每一篇文章中添加“脸谱喜欢”按钮。我已经得到了任何我需要添加的类似按钮,我唯一需要的是,我如何访问函数author_bio_display($content)中当前帖子的链接,即在它写rawurlencode('post permalink goes here')的地方
function author_bio_display($content)
{
$bio_box = '<iframe src="http://www.facebook.com/plugins/like.php?href='. rawurlencode('post permalink goes here') .'&layout=standard&show-faces=true&width=450&action=like&font=arial&colorscheme=light" scrolling="no" frameborder="0" allowTransparency="true" id="facebook-like"></iframe>';
return $content . $bio_box;
}
add_action("the_content", "author_bio_display"); 发布于 2013-09-01 11:35:18
如果您当前在一个详细页面上,比如这里的single.php,我已经定义了一个变量$post并将当前的POST->ID保存在$permalink.Now中,您可以使用它。
function author_bio_display($content)
{
global $post;
$permalink = get_permalink($post->ID);
$bio_box = '<iframe src="http://www.facebook.com/plugins/like.php?href='. rawurlencode('*post permalink*') .'&layout=standard&show-faces=true&width=450&action=like&font=arial&colorscheme=light" scrolling="no" frameborder="0" allowTransparency="true" id="facebook-like"></iframe>';
return $content . $bio_box;
} 发布于 2013-09-01 23:11:07
要获取当前ID而不生成全局$post变量,请执行以下操作:
$id = get_the_id();和
get_permalink($id);大多数非循环函数以"get_“开头,这些函数不回显,而是返回数据。
发布于 2013-09-12 06:53:08
首先,the_content不是Action Hook,而是Filter Hook,所以您应该使用add_filter而不是add_action。
function attach_like_button($content) {
$post_id = $GLOBALS['post']->ID;
$permalink = get_permalink($post_id);
$link_button = ''; // Get latest facebook like button code from https://developers.facebook.com/docs/reference/plugins/like/
return $content.$link_button;
}
add_filter( 'the_content', 'attach_like_button' );https://stackoverflow.com/questions/18557985
复制相似问题