^ 回到顶部
  • 人生没有定律,每个人都有自己的节奏
  • 本站wordpress建站教程均通过实践后发布,希望对你有帮助
  • 希望你的坚持,都是因为热爱,而不是因为不甘心
  • 8年wordpress建站经验,5星服务品质
  • 那些不愿意让你吃亏的人,才是真正值得你深交的人,也是值得你付出时间的人
  • 阿里云2核2g仅需86元/年

wordpress函数add_post_type_support()用法示例

add_post_type_support( string $post_type,  string|array $feature )

Register support of certain features for a post type.


描述

All core features are directly associated with a functional area of the edit screen, such as the editor or a meta box. Features include: ‘title’, ‘editor’, ‘comments’, ‘revisions’, ‘trackbacks’, ‘author’, ‘excerpt’, ‘page-attributes’, ‘thumbnail’, ‘custom-fields’, and ‘post-formats’.

新用户2核2g仅需86元/年    领取1153套模板    免费cdn流量包    ¥3188礼包

Additionally, the ‘revisions’ feature dictates whether the post type will store revisions, and the ‘comments’ feature dictates whether the comments count will show on the edit screen.


参数

$post_type

(string)
(Required)
The post type for which to add the feature.

$feature

(string|array)
(Required)
The feature being added, accepts an array of feature strings or a single string.


源代码

File: wp-includes/post.php

function add_post_type_support( $post_type, $feature ) {
	global $_wp_post_type_features;

	$features = (array) $feature;
	foreach ($features as $feature) {
		if ( func_num_args() == 2 )
			$_wp_post_type_features[$post_type][$feature] = true;
		else
			$_wp_post_type_features[$post_type][$feature] = array_slice( func_get_args(), 2 );
	}
}

更新日志

Version 描述
3.0.0 Introduced.

相关函数

Used By

  • wp-includes/class-wp-post-type.php:
    WP_Post_Type::add_supports()
  • wp-includes/post.php:
    create_initial_post_types()

  1. Skip to note content

    You must log in to vote on the helpfulness of this noteVote results for this note: 0You must log in to vote on the helpfulness of this note

    Contributed by Codex

    This example adds support for excerpts in pages (assuming it is *not* showing under “Screen Options”):

    
    <?php
    add_action('init', 'wpdocs_custom_init');
    
    /**
     * Add excerpt support to pages
     */
    function wpdocs_custom_init() {
    	add_post_type_support( 'page', 'excerpt' );
    }
    ?>
    
  2. Unfortunately,

    add_post_type_support('page', 'thumbnail');

    won’t add featured images to pages. For that you need to [add theme support for post-thumbnails

    add_theme_support( 'post-thumbnails', array( 'post', 'page' ) );

    add_theme_support()

让小雨知道,这篇文章帮到了你
扫码关注微信公众号zs40086(微搜片)随时随地微信看片,抢先福利电影等你来

热门推荐

如有疑问,请前往问答中心反馈!

反馈