首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >根据Wordpress中的帖子类别创建帖子管理菜单

问根据Wordpress中的帖子类别创建帖子管理菜单
EN

Stack Overflow用户
提问于 2019-02-05 08:05:11
回答 2查看 1.7K关注 0票数 3

我试图创建一个新的管理菜单,所有的帖子功能可用,所以我试图创建一个新的菜单,有一个帖子类别‘新闻’和的帖子类型的,所以我增加了下面的功能,但它仍然改变了原来的帖子菜单的命名和功能。

代码语言:javascript
复制
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',
            )
        );
    }
} 
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2019-02-08 10:42:10

“职位”已经被占据了。因此,您不能使用此名称注册另一个post类型。有了这个,你还有三种选择。

选项1:

创建一个自定义的post类型,将“new_posts”或new_posts命名为slug,并将"News“命名为其分类。

更多信息:

选项2

如果您坚持将post类型作为post。您只需创建一个名为"News“的新分类,并将其附加到默认的帖子中。

更多信息:

选项3

这个比其他的稍微复杂一些。

  • 为帖子创建一个名为“新闻”的新类别。
  • 创建一个管理页面。
  • 使用WP_List_Table获取与默认发布和自定义post类型相同的视图。
  • 查询有你的“新闻”类别的文章,并在这里列出。
  • (可选)为目标文章创建编辑页面,以防您不想使用默认的页面。

更多信息:

希望这会有用。编码愉快。

票数 4
EN

Stack Overflow用户

发布于 2019-02-13 12:55:42

很容易在Posts下创建一个新的子菜单来列出(或过滤)它下面的一个类别。只需将以下代码放在主题的“functions.php s.php”中即可。

代码语言:javascript
复制
add_action('admin_menu', 'my_admin_menu'); 
function my_admin_menu() { 
    add_submenu_page('edit.php', 'News', 'News', 'manage_options', 'edit.php?category_name=news'); 
}
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54530001

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档