Warning: Trying to access array offset on false in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 216
post_type_supports() - 检查文章类型对给定功能的支持 - WordPress函数 - WordPress动力
当前浏览:首页 / WordPress函数 / post_type_supports()

post_type_supports( string $post_type, string $feature )

检查文章类型对给定功能的支持


Warning: Undefined array key -1 in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/reference-cat.php on line 185

Warning: Undefined array key 3 in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/reference-cat.php on line 186

Warning: Undefined variable $searchand in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 154

Warning: Undefined array key "b2f7dfdca5567db6f986bb6af13827bd" in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 223

Warning: Undefined variable $searchand in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 154

Warning: Undefined array key "bf54a07380c4a5252b20c594890f77be" in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 223

post_type 文章类型more...

support 支持


参数

$post_type

(string)(必填) 要检查的文章类型。

$feature

(string)(必填) 要检查的功能。


返回

(bool) post类型是否支持给定功能。


更多信息

函数中的$feature变量将接受以下字符串值:

  • ‘title’:标题
  • ‘editor’ (content):编辑(正文内容)
  • ‘author’:作者
  • ‘thumbnail’:缩略图(特色图像)(当前主题还必须支持post-thumbnails)
  • ‘excerpt’:摘录
  • ‘trackbacks’
  • ‘custom-fields’:自定义字段(参见Custom_Fields,又名meta-data)
  • ‘comments’:评论(也将在编辑界面上看到评论计数)
  • ‘revisions’:修订(将存储修订)
  • ‘page-attributes’:页面属性(模板和排序)(层次结构必须为true)
  • ‘post-formats’:文章格式(参见Post_Formats)

请注意,在“thumbnail”值中,您还可以使用‘attachment:audio’和‘attachment:video’。

如果该值不可用,它将返回false。

您可以发送此字段中的任何字符串,除非您正在检查接受的值,否则它将返回false。



源码

查看源码 官方文档


更新日志

版本描述
3.0.0开始引入

使用示例

  • 示例1

    dump所有可能的变量字符串。

    global $_wp_post_type_features;
    var_dump($_wp_post_type_features);
    
  • 示例2

    要检查文章是否支持评论:

    if ( post_type_supports( 'post', 'comments' ) ) {
    	...
    }

    或者,页面是否支持摘录:

    if ( post_type_supports( 'page', 'excerpt' ) ) {
    	...
    }
  • 示例3

    接受的slug:

    'title'
    'editor' (content)
    'author'
    'thumbnail' (featured image) (current theme must also support Post Thumbnails)
    'excerpt'
    'trackbacks'
    'custom-fields' (see Custom_Fields, aka meta-data)
    'comments' (also will see comment count balloon on edit screen)
    'revisions' (will store revisions)
    'page-attributes' (template and menu order) (hierarchical must be true)
    'post-formats' (see Post_Formats)