我正在阅读这篇文章:常见的WordPress开发错误和如何解决它们,他们在其中写道:
获取主题位置:如果您正在使用TEMPLATEPATH或bloginfo('template_directory')。停止!如上例所示,您应该使用非常有用的get_template_directory()。
但是他没有详细说明。有什么不好的bloginfo()
?
我正在阅读这篇文章:常见的WordPress开发错误和如何解决它们,他们在其中写道:
获取主题位置:如果您正在使用TEMPLATEPATH或bloginfo('template_directory')。停止!如上例所示,您应该使用非常有用的get_template_directory()。
但是他没有详细说明。有什么不好的bloginfo()
?
Answers:
为了使长话短说:get_bloginfo( 'template_directory' )
和get_bloginfo( 'template_url' )
简单的返回get_template_directory_uri()
。
因此,您可以简单地通过直接引用后者的模板标签来简化第二个调用。
其他一些:
'url'
=> home_url()
'wpurl'
=> site_url()
'stylesheet_url'
=> get_stylesheet_uri()
'stylesheet_directory'
=> get_stylesheet_directory_uri()
'locale'
=> get_locale()
另请注意:TEMPLATEPATH
和STYLESHEETPATH
预定要弃用,因此最好现在分别用get_template_directory()
和替换它们get_stylesheet_directory()
。
回复:此评论
我刚才要说的是:)。我将添加
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()
。
get_bloginfo()
参数的向后兼容性。