2011-06-08 30 views
0

我有我的投資組合頁面的自定義模板。但是,切換主題後,它已經消失,因爲它位於我之前主題的文件夾中。WordPress的:如何創建一個模板,當你切換主題仍然可用?

從技術上講,我可以將該文件複製到我的新主題文件夾中。但是,我計劃每兩週更換一次主題,這變得不重要。有沒有辦法總是有一堆常見的模板文件可供我使用,無論何時和多久我切換主題? (換句話說,我想創建不依賴主題的模板文件。)

謝謝!

+0

也許有一種方法可以創建一個wp插件,用於在主題更改時複製模板文件,或者將插件文件夾作爲模板文件夾進行操作。 – Arvin 2011-06-08 01:11:44

回答

1

有,使用template_redirect,你將放在functions.php文件。

function uniquename_default_template() { 

global $wpdb; 

if(get_post_type() == 'posttype') : /* You could use is_single() instead of get_post_type() == '' or any type of conditional tag) */ 

include(TEMPLATEDIR . 'path/to/theme/file.php'); /* You could use TEMPLATEDIR to get a file from a template folder, or PLUGINDIR to get a file from the plugins directory - doesn't support HTTP requests */ 

exit; endif; 

} 

add_action('template_redirect', 'uniquename_default_template'); 

希望它有幫助。

相關問題