2011-11-04 43 views
2

我可以有單數字wordpress永久鏈接?試圖強制永久鏈接爲「2」,例如自動將其重寫爲「2-2」。純數字wordpress永久鏈接

尋找到它遠一點,我發現這是任何數值固定鏈接的情況下 - 我認爲它具有與尋呼可能的干擾做,但有一個使用情況下,我想用這個結構..

回答

0

我已經通過攔截後slu創建並以某種方式「固定」它來處理過這一次。也許你可以這樣工作:

/* 
* New permalink structure 
* 
* Itercepts every wp_insert_post data to change the regular slugs to md5 hashes 
* based on the Unix timestamp of action. This generates a new slug at every 
* saving action, which protects the posts against unauthorised direct access. 
* 
*/ 
function rm_cpt_permalink_change($data) { 

    if ($data['post_type'] == 'custom_post_type') { 

       $time = time(); 
     $data['post_name'] = md5($time); 
     return $data; 
    } else { 
      return $data; 
     } 
} 
add_filter('wp_insert_post_data','rm_cpt_permalink_change',10,2); 

你真的需要一位數的slu?嗎?如果您可以使用00001或000005,wp_insert_post_data過濾器可能是您的選擇。

+0

謝謝,我會朝這個方向看。這個問題顯然比我想象的更麻煩。 – Millions

0

你可能已經有了一個'2'的職位;如果它不在後管理小組中,它可能仍然在垃圾箱中。

在旁註中,使用數字作爲slu might可能不是最好的主意 - 它可能與分頁和其他重寫規則相沖突,並且可能不會描述該帖子的用途。

希望這會有所幫助!

+0

謝謝 - 雖然情況並非如此 - 我認爲它與可能的分頁干擾有關,但Wordpress不會允許您僅使用數字唯一的固定鏈接。我有一個特殊的用例,這將是有益的... – Millions

1

實際上,這可以很容易地從設置中的固定鏈接部分完成。你可以簡單地設置/ post_id /作爲永久鏈接結構,它會正常工作。