在Wordpress single中。php贴子页面都用于媒体附件(例如。http://domain.se/postname/imagename/) 和博客帖子页面。
我可以使用什么条件标记来确定一篇文章是否不是媒体附件,而是一篇普通的博客文章?
我之所以要确定这一点,是因为目前我已经定制了单曲。php文件中包含我需要的单个博客帖子的其他字段,现在自定义字段在媒体附件页上也显示为空,这看起来很糟糕。
在Wordpress single中。php贴子页面都用于媒体附件(例如。http://domain.se/postname/imagename/) 和博客帖子页面。
我可以使用什么条件标记来确定一篇文章是否不是媒体附件,而是一篇普通的博客文章?
我之所以要确定这一点,是因为目前我已经定制了单曲。php文件中包含我需要的单个博客帖子的其他字段,现在自定义字段在媒体附件页上也显示为空,这看起来很糟糕。
大多数时候,如果要自定义不同帖子(帖子、页面、附件或自定义帖子类型)的输出,则需要使用特定的模板文件,因为这样更易于维护。例如:
单人。php用于标准帖子,defualt模板用于其他没有特定tempalte文件附件的帖子类型。用于媒体附件的php图像。php用于图像附件页面。php用于页面自定义类型。php用于自定义类型post更多信息Wordpress template hierarchy.
当然,您也可以使用其他答案中建议的或您在问题中建议的条件标记。
if( is_single() ) {
//This is a post of any type except attachment or page
}
if( is_attachment() ) {
//This is an attachment
}
if( is_page() ) {
//This is a page
}
if( is_singular( \'post\' ) ) {
//This is a post (core standard post type)
}
if( is_singular( \'custom-type\' ) ) {
//This is a custom-type post
}
您可以使用conditional tag, 在这种情况下is_singular()
将适合:
is_singular(\'post\')
查看常规时返回truepost
, 因为$post_types
参数设置为它。除了为允许的HTML标记提供粒度控制之外wp_kses 提供超过wp_strip_all_tags? 基本上,如果我使用wp_kses 并将其设置为not 允许任何HTML或协议,它是否比仅使用wp_strip_all_tags?