2012-02-04 18 views
0

WordPress網站最近從.co.uk變爲.org.uk。一旦完成,它會影響Facebook評論數據,因爲它映射到的URL已更改。這是的single.php中的代碼來調用評論:更改WordPress get_bloginfo('url');或永久域名在某個日期之前發佈的帖子

<div class="fb-comments" data-href="<?php the_permalink() ?>" data-num-posts="3" data-width="620"></div> 

現在the_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> 
+0

我不知道如果我失去了一些東西,但它不應該是那麼容易,因爲寫一個小(CLI的)腳本獲取所有wp_posts WHERE永久LIKE domain.co.uk,用.org替換co.uk然後更新wp_posts? – dbrumann 2012-02-04 11:06:04

回答

0

確定開始與 第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步:現在保存並打開環路的single.php或single.php中,你已經把你的Facebook評論股利和替換用下面的代碼。

第4步:保存並運行。

這一定會奏效。

享受。

謝謝 拉胡爾。

+0

啊!第3步之後的代碼行缺少它將是'<?php facebook_comments(); ?>' – Rahul 2012-02-04 11:27:18

+0

好的。那麼現在,複製不同peramlink域的代碼中的變量是什麼。例如http://domain.co.uk/%permalink%/和http://domain.org/%permalink%/(第二個現在可以簡單地是the_permalink()) – manc 2012-02-04 11:44:36

0

你不能這樣做

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> 
} 
+0

好吧 - 所以從這個我怎麼可以使用基於新域名的永久鏈接結構?即domain.co.uk/%postname%/和the_permalink? – manc 2012-02-04 11:53:59

相關問題