如何在Wordpress博客页面中为每个facebook类设置图像、描述和标题?
可能重复:如何在Wordpress博客页面中为每个facebook类设置图像、描述和标题?,facebook,wordpress,facebook-like,meta-tags,Facebook,Wordpress,Facebook Like,Meta Tags,可能重复: 因此,当用户点击主博客页面上的某篇文章时,我想为每篇文章设置一个不同的图像、标题和描述。这与Mashable和Techcrunch的方式相同。到目前为止,我只能找到解决方案,包括在头部添加一个元标记。但问题是主页上有许多帖子,每个帖子都有不同的标题、图片等。我这样做吗?有人知道吗?我猜你必须为每个帖子手动设置类似的内容 对于每一项,做如下操作 <div id="post-id"> <h2>title</h2> <img c
因此,当用户点击主博客页面上的某篇文章时,我想为每篇文章设置一个不同的图像、标题和描述。这与Mashable和Techcrunch的方式相同。到目前为止,我只能找到解决方案,包括在头部添加一个元标记。但问题是主页上有许多帖子,每个帖子都有不同的标题、图片等。我这样做吗?有人知道吗?我猜你必须为每个帖子手动设置类似的内容 对于每一项,做如下操作
<div id="post-id">
<h2>title</h2>
<img class="thumb" src="src.jpg">
<p class="excerpt">the description</p>
<a class="permalink" href="permalink">Read more</a>
<a href="#" class="share">
</div>
现在,这个jQuery是不对的(我很肯定),你需要有Facebook应用程序和所有的设置。但我想这种方法会很有效
或者找到一个插件,比如addthis.com或facebook“like”插件,如果你插入permalink,它可能会工作。
我猜你必须为每个人手动设置类似的设置 对于每一项,做如下操作
<div id="post-id">
<h2>title</h2>
<img class="thumb" src="src.jpg">
<p class="excerpt">the description</p>
<a class="permalink" href="permalink">Read more</a>
<a href="#" class="share">
</div>
现在,这个jQuery是不对的(我很肯定),你需要有Facebook应用程序和所有的设置。但我想这种方法会很有效
或者找到一个插件,比如addthis.com或facebook“like”插件,如果你插入permalink,它可能会工作。
您可以编写一个函数,用于拍摄文章的图片、标题和描述,并将其动态插入部分:
function insert_fb_in_head()
{
if (is_singular()) {
$image = get_the_post_thumbnail();
$title = get_the_title();
$type = 'article';
}
else {
$image = 'standard_image.jpg';
$title = bloginfo('name');
$type = 'blog';
}
echo '<meta property="og:title" content="'.$title.'"/>';
echo '<meta property="og:type" content="'.$type.'"/>';
echo '<meta property="og:url" content="'.get_permalink().'"/>';
echo '<meta property="og:site_name" content="'.$title.'"/>';
echo '<meta property="og:email" content="yours@example.com"/>';
echo '<meta property="og:phone_number" content="000 555 888"/>';
echo '<meta property="og:description" content="'.meta_description().'"/>';
echo '<meta property="og:image" content="' . $image . '"/>';
}
add_action( 'wp_head', 'insert_fb_in_head', 5 );
这里可能有更好的方法来定义标题、图像和描述,但我认为这会给你一个方法。至少我对这种方式很满意
PS:为了澄清,根据需要更改变量,并将其放入模板的functions.php文件中,就这样。一旦有人点击你希望已经插入到你博客中的“喜欢”按钮,标题、图片和描述就会出现在他/她的facebook墙上 您可以编写一个函数,用于拍摄帖子的图片、标题和描述,并将其动态插入到部分中:
function insert_fb_in_head()
{
if (is_singular()) {
$image = get_the_post_thumbnail();
$title = get_the_title();
$type = 'article';
}
else {
$image = 'standard_image.jpg';
$title = bloginfo('name');
$type = 'blog';
}
echo '<meta property="og:title" content="'.$title.'"/>';
echo '<meta property="og:type" content="'.$type.'"/>';
echo '<meta property="og:url" content="'.get_permalink().'"/>';
echo '<meta property="og:site_name" content="'.$title.'"/>';
echo '<meta property="og:email" content="yours@example.com"/>';
echo '<meta property="og:phone_number" content="000 555 888"/>';
echo '<meta property="og:description" content="'.meta_description().'"/>';
echo '<meta property="og:image" content="' . $image . '"/>';
}
add_action( 'wp_head', 'insert_fb_in_head', 5 );
这里可能有更好的方法来定义标题、图像和描述,但我认为这会给你一个方法。至少我对这种方式很满意
PS:为了澄清,根据需要更改变量,并将其放入模板的functions.php文件中,就这样。一旦有人点击你希望已经插入到你博客中的“喜欢”按钮,标题、图片和描述就会出现在他/她的facebook墙上