php – 根据WordPress中的帖子类别为Post创建管理员菜单
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了php – 根据WordPress中的帖子类别为Post创建管理员菜单,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3444字,纯文字阅读大概需要5分钟。
内容图文
![php – 根据WordPress中的帖子类别为Post创建管理员菜单](/upload/InfoBanner/zyjiaocheng/741/94b06a1450f146f384db2e536561122b.jpg)
我正在尝试创建一个包含所有后期功能的新管理菜单所以我正在尝试创建一个新的菜单,其中包含一个帖子类别’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',
)
);
}
}
解决方法:
“邮政”已经被采取.因此,您无法使用此名称注册其他帖子类型.因此,除此之外,您还有其他三种选择.
选项1:
创建一个自定义帖子类型,将“New Posts”或new_posts命名为slug,将“News”命名为其分类.
更多信息:
>如何注册自定义帖子类型(Codex Site)
>如何注册自定义帖子类型(Developer Site)
>如何注册自定义分类法(Codex Site)
>如何注册自定义分类(Developer Site)
选项2
如果您坚持将帖子类型作为帖子.您可以创建一个名为“新闻”的新分类,并将其附加到默认帖子.
更多信息:
>如何注册自定义分类法(Codex Site)
>如何注册自定义分类(Developer Site)
选项3
这个比其他人稍微复杂一点.
>为帖子创建一个名为“新闻”的新类别.
>创建管理页面.
>使用WP_List_Table获取与默认帖子和自定义帖子类型相同的视图.
>查询具有“新闻”类别的帖子并在此处列出.
>(可选)如果您不想使用默认帖子,请为目标帖子创建编辑页面.
更多信息:
>行政菜单(Codex Site)
>如何创建新的管理菜单页面(Developer Site)
>如何使用WP_List_Table(Codex Site)
>如何使用WP_List_Table(Developer Site)
希望这会有用.快乐的编码.
内容总结
以上是互联网集市为您收集整理的php – 根据WordPress中的帖子类别为Post创建管理员菜单全部内容,希望文章能够帮你解决php – 根据WordPress中的帖子类别为Post创建管理员菜单所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。