WordPress 自定义文章类型与自己的列表

问题描述 投票:0回答:1

我在我的主题有一个自定义的帖子类型称为 "食谱"。我可以添加文本,缩略图和添加类别。我想添加一个成分列表到这个帖子类型。我需要一个全局的成分列表,我可以使用一个单一的食谱。我怎样才能为自定义的帖子类型创建一个全局列表,就像分类一样,但只是配料?

这是我的帖子类型的代码。

<?php
add_action( 'init', 'my_recipes' );
add_filter( 'post_updated_messages', 'my_recipes_messages' );
add_action( 'admin_head', 'my_recipes_help' );

function my_recipes() {
$labels = array(
'name'               => 'Recipes',
'singular_name'      => 'Recipe',
'menu_name'          => 'Recipes',
'name_admin_bar'     => 'Recipe',
'add_new'            => 'Add New',
'add_new_item'       => 'Add New Recipe',
'new_item'           => 'New Recipe',
'edit_item'          => 'Edit Recipe',
'view_item'          => 'View Recipe',
'all_items'          => 'All Recipes',
'search_items'       => 'Search Recipes',
'parent_item_colon'  => 'Parent Recipes:',
'not_found'          => 'No recipes found.',
'not_found_in_trash' => 'No recipes found in Trash.'
);

$args = array(
'labels'        => $labels,
'public'        => true,
'rewrite'       => array( 'slug' => 'recipe' ),
'has_archive'   => true,
'menu_position' => 20,
'menu_icon'     => 'dashicons-carrot',
'taxonomies'        => array( 'post_tag', 'category' ),
'supports'      => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt')
);
register_post_type( 'my_recipe', $args );
}

function my_recipes_messages( $messages ) {
$post = get_post();

$messages['recipe'] = array(
0  => '',
1  => 'Recipe updated.',
2  => 'Custom field updated.',
3  => 'Custom field deleted.',
4  => 'Recipe updated.',
5  => isset( $_GET['revision'] ) ? sprintf( 'Recipe restored to revision from %s',wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
6  => 'Recipe published.',
7  => 'Recipe saved.',
8  => 'Recipe submitted.',
9  => sprintf(
'Recipe scheduled for: <strong>%1$s</strong>.',
date_i18n( 'M j, Y @ G:i', strtotime( $post->post_date ) )
),
10 => 'Recipe draft updated.'
);

return $messages;
}

function my_recipes_help() {

$screen = get_current_screen();

if ( 'recipe' != $screen->post_type ) {
return;
}

$basics = array(
'id'      => 'recipe_basics',
'title'   => 'Recipe Basics',
'content' => 'Content for help tab here'
);

$formatting = array(
'id'      => 'recipe_formatting',
'title'   => 'Recipe Formatting',
'content' => 'Content for help tab here'
);

$screen->add_help_tab( $basics );
$screen->add_help_tab( $formatting );

}
php wordpress plugins custom-post-type
1个回答
1
投票

如果你想有一个全局的成分列表,你可以添加,如你所提到的,像类别或标签,那么你正在寻找一个自定义分类法。

试试这个工具。https:/generatewp.comtaxonomy。

© www.soinside.com 2019 - 2024. All rights reserved.