php 管理员类,php – 根据WordPress中的帖子类别为Post创建管理员菜单

我正在尝试创建一个包含所有后期功能的新管理菜单所以我正在尝试创建一个新的菜单,其中包含一个帖子类别’news’和post-type – post

所以我添加了下面的功能,但它仍然改变了原始帖子菜单的命名和功能.

function custom_post_type()

{

$labels = array(

'name' => _x( 'News', 'Post Type General Name', 'texdomain' ),

'singular_name' => _x( 'News', 'Post Type Singular Name', 'texdomain' ),

'menu_name' => __( 'News', 'texdomain' ),

'parent_item_colon' => __( 'Parent News', 'texdomain' ),

'all_items' => __( 'All News', 'texdomain' ),

'view_item' => __( 'View News', 'texdomain' ),

'add_new_item' => __( 'Add New News', 'texdomain' ),

'add_new' => __( 'Add New', 'texdomain' ),

'edit_item' => __( 'Edit News', 'texdomain' ),

'update_item' => __( 'Update News', 'texdomain' ),

'search_items' => __( 'Search News', 'texdomain' ),

'not_found' => __( 'Not Found', 'texdomain' ),

'not_found_in_trash' => __( 'Not found in Trash', 'texdomain' ),

);

// Set other options for Custom Post Type

$args = array

(

'label' => __( 'News', 'texdomain' ),

'description' => __( 'News news and reviews', 'texdomain' ),

'labels' => $labels,

// Features this CPT supports in Post Editor

'supports' => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'comments', 'revisions', 'custom-fields', 'category'),

// You can associate this CPT with a taxonomy or custom taxonomy.

'taxonomies' => array( 'genres' ),

/* A hierarchical CPT is like Pages and can have

* Parent and child items. A non-hierarchical CPT

* is like Posts.

*/

'hierarchical' => false,

'public' => true,

'show_ui' => true,

'show_in_menu' => true,

'show_in_nav_menus' => true,

'show_in_admin_bar' => false,

'menu_position' => 5,

'can_export' => true,

'has_archive' => true,

'exclude_from_search' => false,

'publicly_queryable' => true,

'capability_type' => 'page',

);

// Registering your Custom Post Type

register_post_type( 'Post', $args );

}

/* Hook into the 'init' action so that the function

* Containing our post type registration is not

* unnecessarily executed.

*/

add_action( 'init', 'custom_post_type', 0 );

function custom_post_news_search( $query ) {

global $wp_query;

if( is_admin() && $query->is_main_query() && isset( $_GET['post_type'] ) ) {

// $strSearchUrl = esc_attr($_GET['post_type']);

$wp_query = new WP_Query(

array(

'post_type' => 'post',

'category_name' => 'News',

)

);

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值