繁体   English   中英

如何在管理菜单中添加自定义帖子类型?

[英]How do I add a custom post type to the admin menu?

我的文件是否放在错误的文件夹中?

添加所有这些代码后,它们最终以文本形式出现在我的管理菜单上。 我尝试将其直接放入我的functions.php ,也将其放入一个名为function.php的文件中,这就是本教程所说的内容,我认为这是一个错字。

themes/theme-name/wp-includes/post.php
function ttlm_register_team_custom_type() {
    $labels = array(
        'name'               => _x( 'Teams', 'post type general name', 'your-plugin-textdomain' ),
        'singular_name'      => _x( 'Team', 'post type singular name', 'your-plugin-textdomain' ),
        'menu_name'          => _x( 'Teams', 'admin menu', 'your-plugin-textdomain' ),
        'name_admin_bar'     => _x( 'Team', 'add new on admin bar', 'your-plugin-textdomain' ),
        'add_new'            => _x( 'Add New', 'team', 'your-plugin-textdomain' ),
        'add_new_item'       => __( 'Add New Team', 'your-plugin-textdomain' ),
        'new_item'           => __( 'New Team', 'your-plugin-textdomain' ),
        'edit_item'          => __( 'Edit Team', 'your-plugin-textdomain' ),
        'view_item'          => __( 'View Team', 'your-plugin-textdomain' ),
        'all_items'          => __( 'All Teams', 'your-plugin-textdomain' ),
        'search_items'       => __( 'Search Teams', 'your-plugin-textdomain' ),
        'parent_item_colon'  => __( 'Parent Teams:', 'your-plugin-textdomain' ),
        'not_found'          => __( 'No teams found.', 'your-plugin-textdomain' ),
        'not_found_in_trash' => __( 'No teams found in Trash.', 'your-plugin-textdomain' )
    );

    $args = array(
        'labels'             => $labels,
        'public'             => true,
        'publicly_queryable' => true,
        'show_ui'            => true,
        'show_in_menu'       => true, 
        'query_var'          => true,
        'rewrite'            => array( 'slug' => 'ttlm_team' ),
        'capability_type'    => 'post',
        'has_archive'        => true,
        'hierarchical'       => false,
        'menu_position'      => null,
        'supports'           => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments' )
    );

    register_post_type( 'ttlm_team', $args );
}

add_action( 'init', 'ttlm_register_team_custom_type' );
themes/theme-name/functions.php
/*-----------------------------------------------*/
/* Custom Post Types
/*-----------------------------------------------*/
require_once('wp-includes/post.php');

WP管理员显示代码

将代码包括在:

<?php

//your functions

?>

希望能帮助到你

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM