我们可以为不同浏览器设定不同的wordpress主题。
代码如下:
<?php /* Plugin Name: Serve themes to browsersPlugin URI: http://www.xianren.org/fjianshe/serve-themes-to-browsers.html Description: This plugin will serve the default theme to any visitors using IE6. Author: Nathan Rice Author URI: http://www.nathanrice.net/ Version: 1.0 */ add_filter('template', 'serve_default_to_iesix'); add_filter('option_template', 'serve_default_to_iesix'); add_filter('option_stylesheet', 'serve_default_to_iesix'); function serve_default_to_iesix($theme) { if(strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 6') !== false) $theme = 'anear'; if(strpos($_SERVER['HTTP_USER_AGENT'], 'Firefox') !== false) $theme = 'xianrensea'; if(strpos($_SERVER['HTTP_USER_AGENT'], 'chrome') !== false) $theme = 'default'; if(strpos($_SERVER['HTTP_USER_AGENT'], 'Safari') !== false) $theme = 'anear'; if(strpos($_SERVER['HTTP_USER_AGENT'], 'Opera') !== false) $theme = 'anear'; return $theme; } ?>
将对应浏览器下边的$theme改成你Wordpress的theme安装目录下其他主题的文件夹名即可。例如,如果你想为ie6用户指定Twenty Ten主题,此主题所在的文件夹名twentyten,将$theme = ‘anear’改成$theme = ‘twentyten’即可。
这些代码的使用方法为,新建php文档,拷贝上段代码存到文档中,修改其中的$theme,上传到插件目录plugins/中,后台插件启用就OK了。。。很简单吧?
编程知识库是国内专业的网站建设资源编程技术学习类网站