GET_TEMPLATE_DIRECTORY()VS BLOGINO(‘TEMPLATORIRECTORY’)VS TEMPLATEPATH

时间:2012-11-15 作者:coopersita

我在读这篇文章:Common WordPress Development Mistakes and How to Fix Them, 他们在书中写道:

获取主题位置:如果您使用的是TEMPLATEPATH或bloginfo(“template\\u目录”)。Stop! 您应该使用非常有用的get\\u template\\u directory(),如上面的示例所示。

但他没有详细说明。有什么不好的bloginfo()?

1 个回复
最合适的回答,由SO网友:Chip Bennett 整理而成

长话短说:get_bloginfo( \'template_directory\' )get_bloginfo( \'template_url\' ) 只需返回get_template_directory_uri().

因此,只需直接引用后一个模板标记,就可以简化第二个调用。

Refer to source for get_bloginfo().

其他一些:

  • \'url\' => home_url()
  • \'wpurl\' => site_url()
  • \'stylesheet_url\' => get_stylesheet_uri()
  • \'stylesheet_directory\' => get_stylesheet_directory_uri()
  • \'locale\' => get_locale()

编辑

注意:TEMPLATEPATH and STYLESHEETPATH are slated for deprecation, 因此,您最好现在用get_template_directory()get_stylesheet_directory(), 分别地

编辑2关于:此评论

正是我要说的:)。我想补充一点get_template_directory() 返回路径和get_template_directory_uri() url。所以作者的观点并不一致:get_bloginfo( \'template_directory\' )get_template_directory() 返回不同的东西!

返回到源:)

case \'template_directory\':
case \'template_url\':
    $output = get_template_directory_uri();
    break;
回复:此评论:

开发儿童主题时需要注意的一点get_stylesheet_directory() 明确地如果我错了,有人纠正我。

没错,但一直都是这样。get_bloginfo() 不返回任何与get_stylesheet_directory(). 它只返回get_stylesheet_uri()get_stylesheet_directory_uri().

结束

相关推荐

模板标签TEMPLATE_DIRECTORY拉取错误路径

我正在制作一个主题索引。当我使用“template\\u directory”时,它实际上并不是拉取文件的url路径,而是拉取主域名。因此 http://example.com/wp-content/themes/theme_name/images/pic.jpg 它会拉取域url并显示http://example.com/images/pic.jpg 我不明白为什么它会这样做,因为索引。php文件实际上位于正确的目录中。(位于主题文件夹中)。这是索引。wordpress目录中的php