【问题标题】:Adding supports post-tag in custom menu wordpress dashboard在自定义菜单 wordpress 仪表板中添加支持后标记
【发布时间】:2017-11-20 02:59:35
【问题描述】:

如何添加支持以在帖子中添加标签。我尝试了一切,但后标签选项仍然不可见/出现。

register_post_type( 'articles',
    array(
        'labels' => array(
            'name' => __( 'Articles' ),
            'singular_name' => __( 'Articles' )
        ),
        'supports' => array( 'title', 'editor', 'thumbnail', 'comments', 'revisions', 'excerpt','page-attributes','post-formats','custom-field' ),
        'public' => true,
        'has_archive' => true,
        'rewrite' => array('slug' => 'articles'),
    )
);

【问题讨论】:

    标签: wordpress tags


    【解决方案1】:

    在此代码中,您可以使用自定义标签选项获取自定义帖子类型。

    试试这个代码,

    //* Create Custom Post Type
    add_action( 'init', 'add_custom_post_type' );
    function add_custom_post_type() {
    
    	register_post_type( 'members',
    		array(
    			'labels' => array(
    				'name'          => __( 'Members', 'wpsites' ),
    				'singular_name' => __( 'Member', 'wpsites' ),
    			),
    			'has_archive'  => true,
    			'hierarchical' => true,
                            'menu_icon'    => 'dashicons-admin-users',
    			'public'       => true,
    			'rewrite'      => array( 'slug' => 'members', 'with_front' => false ),
    			'supports'     => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'trackbacks', 'custom-fields', 'revisions', 'page-attributes' ),
    			'taxonomies'   => array( 'member-type' ),
                            'menu_position' => 2,
    
    		));
    
    }
    
    add_action( 'init', 'create_custom_tag' );
    
    function create_custom_tag() {
    	register_taxonomy(
    		'tag',
    		'members',
    		array(
    			'label' => __( 'Tag' ),
    			'rewrite' => array( 'slug' => 'tag' ),
    			'hierarchical' => true,
    		)
    	);
    }

    它会为你工作

    【讨论】:

      【解决方案2】:

      您需要在注册函数中添加 post_tag 分类:

      register_post_type( 'articles',
          array(
              'labels' => array(
                  'name' => __( 'Articles' ),
                  'singular_name' => __( 'Articles' )
              ),
              'supports' => array( 'title', 'editor', 'thumbnail', 'comments', 'revisions', 'excerpt','page-attributes','post-formats','custom-field' ),
              'taxonomies'=>array('post_tag'),
              'public' => true,
              'has_archive' => true,
              'rewrite' => array('slug' => 'articles'),
          )
      );
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2014-01-13
        • 1970-01-01
        • 1970-01-01
        • 2022-07-12
        • 2015-01-11
        • 1970-01-01
        • 2018-06-09
        相关资源
        最近更新 更多