更改WordPress获取博客信息(“url”);或permalink域,用于特定日期之前发布的帖子
WordPress网站最近从.co.uk改为.org。一旦这样做,它就会影响Facebook的评论数据,因为它所映射的URL已经改变。以下是single.php中调用注释的代码:更改WordPress获取博客信息(“url”);或permalink域,用于特定日期之前发布的帖子,wordpress,Wordpress,WordPress网站最近从.co.uk改为.org。一旦这样做,它就会影响Facebook的评论数据,因为它所映射的URL已经改变。以下是single.php中调用注释的代码: <div class="fb-comments" data-href="<?php the_permalink() ?>" data-num-posts="3" data-width="620"></div> 既然_permalink已经更改,我想将以下内容作为函数输出: if p
<div class="fb-comments" data-href="<?php the_permalink() ?>" data-num-posts="3" data-width="620"></div>
既然_permalink已经更改,我想将以下内容作为函数输出:
if post is published before 29th Jan 2012 output this:
<div class="fb-comments" data-href="http://www.domain.co.uk/post-permalink/" data-num-posts="3" data-width="620"></div>
otherwise output this:
<div class="fb-comments" data-href="http://www.domain.org/post-permalink/" data-num-posts="3" data-width="620"></div>
好的,开始吧
步骤1:打开您正在使用的主题文件夹。
步骤2:在任何编辑器中打开function.php,并在那里复制以下函数
if(! function_exists('facebook_comments')):
function facebook_comments(){
$org_post_date = strtotime(get_the_date());
$earlier_date = strtotime("29 January 2012");
if($org_post_date <= $earlier_date)
{
echo '<div class="fb-comments" data-href="http://www.domain.co.uk/post-permalink/" data-num-posts="3" data-width="620"></div>
';
}
else
{
echo '<div class="fb-comments" data-href="http://www.domain.org/post-permalink/" data-num-posts="3" data-width="620"></div>';
}
}
endif;
步骤3:现在保存它并打开你的loop-single.php或single.php,在那里你已经放置了你的facebook评论div,并用下面的代码替换它
步骤4:保存并运行
这肯定会奏效的
享受
谢谢
拉胡尔。你不能做类似的事情吗
if(the_time('F j, Y') => date([date format here which matches the_time() function], mktime(0,0,0, 1, 29, 2012)))
{
<div class="fb-comments" data-href="http://www.domain.org/post-permalink/" data-num-posts="3" data-width="620"></div>
}
else
{
<div class="fb-comments" data-href="http://www.domain.co.uk/post-permalink/" data-num-posts="3" data-width="620"></div>
}
我不知道我是否遗漏了什么,但这难道不应该像编写一个小的cli脚本获取所有wp_帖子一样简单吗?permalink如domain.co.uk,将co.uk替换为.org it,然后更新wp_帖子?啊!!步骤3后的代码行丢失,它将正常运行。那么现在,代码中复制不同peramlink域的变量是什么。例如,第二个可以是_permalinkok-因此,我如何使用基于新域的permalink结构?i、 e.domain.co.uk/%postname%/和_permalink?