2010-06-28 17 views
6

我添加自定義post_type WordPress的,並想將固定鏈接結構看起來像這樣:在自定義使用日期在WordPress的永久鏈接post_type 3.0

/%post_type%/%year%/%monthnum%/%postname%/ 

我無法弄清楚如何添加日期標籤。使用此代碼,給我/my_type/example-post-slug/

register_post_type('customtype', array(
    ...other options... 
    'rewrite' => array('slug' => 'my_type'), 
)); 

如何包含日期?

回答

-2

使用此它的工作100%:

'rewrite' => array('slug'=>date('Y').'/'.date('m').'/custom_post_type_slug','with_front'=>true) 
0

我發現了一個部分解決方案,允許在地址欄中加載頁面時識別並保留固定鏈接,但不會在編輯屏幕或其他網站上的帖子鏈接中更新。 將以下內容添加到functions.php或特定於站點的插件中,用您的帖子類型的標識替換example-post-type。

function example_rewrite() { 
    add_rewrite_rule('^example-post-type/([0-9]{4})/([0-9]{1,2})/([^/]*)/?','index.php?post_type=example-post-type&year=$matches[1]&monthnum=$matches[2]&name=$matches[3]','top'); 
} 
add_action('init', 'example_rewrite'); 

這將使用重寫API文檔here 要找到了解過程中看到here更多提示。

要記住的一件事是,無論你如何做到這一點,兩個職位不可能有相同的slu,,即使他們有不同的日期。這是因爲如果永久鏈接方案發生了變化,它們可能會發生衝突並導致錯誤。

相關問題