我们在制作wordpress主题时有时需要对指定的模板文件做处理,wp有一个全局变量” $template “,这个全局变量存储着当前调用模板的绝对路径。可以利用这个全局全局变量在functions.php里做个判断。

global $template;
if (basename($template) == 'index.php') {
        wp_enqueue_style('index_css');
    }else{
        wp_enqueue_style('tlevel_css');
    }

发表回复

后才能评论