上一篇文章是《WordPress 路径相关函数总结(一):站点路径相关函数》,今天这一篇则是针对WordPress 主题的函数,对于开发WordPress 主题的开发者很有帮助;相关函数也可以在WordPress 官方文档找到相应的更详细的用法。
还是以本站 http://devework.com 为例子:
获取存放主题的目录URI
echo get_theme_root_uri(); //输出:http://devework.com/wp-content/themes |
---|
获取存放主题的目录的服务器绝对路径
echo get_theme_root(); //输出:<tt>/home/user/public_html/wp-content/themes</tt> |
---|
获取主题目录的目录名称,如果你的主题目录是/wp-content/themes,则
echo get_theme_roots(); //输出:/themes |
---|
获取当前启用的主题目录的服务器绝对路径,例如
/home/user/public_html/wp-content/themes/twentyeleven |
---|
可以用来include文件,例如
<?php include( get_stylesheet_directory() . '/includes/myfile.php'); ?> |
---|
获取当前启用的主题目录的URI,例如
echo get_stylesheet_directory_uri(); //输出:http:/devework.com/wp-content/themes/twentyeleven |
---|
可以使用在需要主题目录URI的场合,例如图片
<img src="<?php echo get_stylesheet_directory_uri() ?>/images/aternus.png" alt="" title="" width="" height="" /> |
---|
如果当前启用的主题是一个child theme,该函数返回parent theme的主题目录URI,用法与get_stylesheet_directory_uri()类似。
如果当前启用的主题是一个child theme,该函数返回parent theme的主题目录的服务器绝对路径,用法与get_stylesheet_directory()类似。
获取当前启用主题的主题目录名称,例如现在启用的主题为twentyeleven,则
echo get_stylesheet(); //输出:twentyeleven |
---|
获取当前启用主题的主题目录名称,与get_template()的区别是,如果用了child theme,则返回child theme的目录名称。
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有