wordpress常用路径函数总结

<?php
    // 不允许直接访问此文件。
    if ( ! defined( 'ABSPATH' ) ) {
	      exit( '拒绝直接访问此脚本.' );
    }    
    /**
     * 定义框架常用的几个路径,你也可以添加自己的路径在此
     * 
     */
    //定义框架文件夹,默认为主题目录下的redux
    
    /** 以下为常用路径函数总结,可参考添加自己用到的变量。*/
    
    
    //主题常用路径总结
    $op_home_url = home_url();  //输出: http://www.xxxx.com
    $op_images_url = home_url('/images/');  //输出: http://www.xxxx.com/images/
    $op_site_url = site_url(); //如果WordPress安装在子目录下,返回http://www.xx.com/wordpress,相当于后台->设置->常规中的“WordPress 地址(URL)”。
    $op_admin_url = admin_url(); //输出:http://www.solagirl.net/wp-admin/
    $op_content_url = content_url(); //输出:http://www.solagirl.net/wp-content 如果在wp-config.php中改变了wp-content目录的位置,则该函数会返回正确地址
    $op_includes_url = includes_url( '/js/'); //输出:http://www.solagirl.net/wp-includes/js/
    
    $op_wp_upload_dir = wp_upload_dir();
    /** 可用参数
    * 示例:$upload_dir = wp_upload_dir();  
    * echo $upload_dir['baseurl'];  //输出:http://www.solagirl.net/wp-content/uploads
    * 'path' - 上传目录的服务器绝对路径,通常以反斜杠(/)开头
    * 'url' - 上传目录的完整URL
    * 'subdir' - 子目录名称,通常是以年/月形式组织的目录地址,例如/2012/07
    * 'basedir' - 上传目录的服务器绝对路径,不包含子目录
    * 'baseurl' - 上传目录的完整URL,不包含子目录
    * 'error' - 报错信息.
    */
    
    $op_get_theme_root_uri = get_theme_root_uri(); //获取存放主题的目录URI 输出:http://www.solagirl.net/wp-content/themes
    $op_get_theme_root = get_theme_root(); //获取存放主题的目录的服务器绝对路径 输出:<tt>/home/user/public_html/wp-content/themes</tt>
    $op_get_theme_roots = get_theme_roots(); //获取主题目录的目录名称,如果你的主题目录是/wp-content/themes,则输出:/themes
    
    $op_get_stylesheet_directory = get_stylesheet_directory(); 
    /** //获取当前启用的主题目录的服务器绝对路径,
    * /home/user/public_html/wp-content/themes/twentyeleven
    * 可以用来include文件,例如
    * <?php include( get_stylesheet_directory() . '/includes/myfile.php'); ?>
    */
    
    $op_get_stylesheet_directory_uri = get_stylesheet_directory_uri();
    /** //获取当前启用的主题目录的URI 
    * 输出:http://www.solagirl.net/wp-content/themes/twentyeleven
    * 可以使用在需要主题目录URI的场合,例如图片
    * <img src="<?php echo get_stylesheet_directory_uri() ?>/images/aternus.png" alt="" title="" width="" height="" />
    */
    
    $op_GET_TEMPLATE_DIRECTORY_URI = GET_TEMPLATE_DIRECTORY_URI(); //如果当前启用的主题是一个child theme,该函数返回parent theme的主题目录URI,用法与get_stylesheet_directory_uri()类似。
    $op_GET_TEMPLATE_DIRECTORY = GET_TEMPLATE_DIRECTORY(); //如果当前启用的主题是一个child theme,该函数返回parent theme的主题目录的服务器绝对路径,用法与get_stylesheet_directory()类似。
    $op_get_stylesheet = get_stylesheet();//获取当前启用主题的主题目录名称,与get_template()的区别是,如果用了child theme,则返回child theme的目录名称。
    $op_get_template = get_template();//获取当前启用主题的主题目录名称,例如现在启用的主题为twentyeleven,则输出:twentyeleven
    
    //插件常用路径总结
    $op_plugins_url() = plugins_url(); //输出:http://www.solagirl.net/wp-content/plugins
    $op_plugins_url('',__FILE__) = plugins_url(); //输出:http://www.solagirl.net/wp-content/plugins/myplugin
    $op_plugins_url('js/myscript.js',__FILE__); = plugins_url(); //输出:http://www.solagirl.net/wp-content/plugins/myplugin/js/myscript.js
    $op_plugin_dir_url( __FILE__ ) = plugin_dir_url( __FILE__ ); //输出:(注意结尾有反斜杠):http://www.solagirl.net/wp-content/plugins/myplugin/
    
    
    $op_plugin_dir_path( __FILE__ ) = plugin_dir_path( __FILE__ ); 
    /** 
    * 输出:/home/user/public_html/wp-content/plugins/myplugin/
    * 可以用来include文件,例如
    * <?php
        define( 'MYPLUGINNAME_PATH', plugin_dir_path(__FILE__) );
        require MYPLUGINNAME_PATH . 'includes/class-metabox.php';
        require MYPLUGINNAME_PATH . 'includes/class-widget.php';
      ?>
    */
    
    
    $op_plugin_basename(__FILE__) = plugin_basename(__FILE__); 
    /** 
    * 返回调用该函数的插件文件名称(包含插件路径)
      例如在插件myplugin下的myplugin.php文件中调用该函数,结果如下
      echo plugin_basename(__FILE__); 
      //输出:myplugin/myplugin.php
      如果在myplugin/include/test.php文件中调用(test.php通过include引用到myplugin.php中),结果如下
      echo plugin_basename(__FILE__);
      //输出:myplugin/include/test.php
    */
    $op_redux_path = get_template_directory() . '/redux';
    $op_redux_path = get_template_directory() . '/redux';
    
    
    $op_redux_path = get_template_directory() . '/redux';
    //定义框架文件夹,默认为主题目录下的redux
    $op_plugins_path = get_template_directory() . '/redux/plugins';
    //定义框架文件夹,默认为主题目录下的redux
    $op_themes_path = get_template_directory() . '/redux/themes';
    //定义框架文件夹,默认为主题目录下的redux
    $op_uploads_path = get_template_directory() . '/redux/uploads';
    //定义框架文件夹,默认为主题目录下的redux
    $op_languages_path = get_template_directory() . '/redux/languages';
    //定义框架文件夹,默认为主题目录下的redux
    $op_wp_content_path = get_template_directory() . '/redux';
    //定义框架文件夹,默认为主题目录下的redux
    $op_wp_includes = get_template_directory() . '/redux';

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值