开发者

Wordpress: how to create a template that is still available when you switch theme?

I have a custom template for my portfolio page. However, after switching theme, it's gone because it is in my previous theme's folder.

Technically, I can copy that file into my new theme folder. However, I plan to change theme every two weeks and this becomes non-trivial. Is there a way to always have a bunch of common template files available to me no matter when and how often I switch theme? (In other words, I want to 开发者_如何学Pythoncreate template files that are not dependent on themes.)

Thanks!


There is, using template_redirect, which you would put in the functions.php file.

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');

Hope it helps.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜