管理菜单中的单个类别的帖子列表

时间:2017-07-27 作者:Fabio Marzocca

我的网站中的“作者”只能添加/编辑单个类别(即新闻)中的帖子。我正在为他们准备后端,我想删除“帖子”菜单,并在其位置显示“新闻”菜单,作者只能从中列出和添加/编辑该类别的帖子。

删除“管理”菜单中的菜单项没有问题,但如何才能达到仅显示新闻类别帖子的目标?

谢谢

1 个回复
最合适的回答,由SO网友:Nuno Sarmento 整理而成

最好的方法是创建一个自定义的帖子类型“News”,并隐藏“posts”菜单项-下面的代码将创建一个自定义的新闻帖子类型

/*
* Creating a function to create our CPT
*/

function custom_post_type() {

// Set UI labels for 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\', ),

// 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\'   => true,
    \'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( \'News\', $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 );
为了对作者隐藏post菜单项,简单的方法是使用此插件-https://wordpress.org/plugins/adminimize/ 或者您可以使用自定义功能完成此操作,更多信息请访问此网站https://www.wpmayor.com/how-to-remove-menu-items-in-admin-depending-on-user-role/

结束

相关推荐

通过WP CLI安装WordPress时,mysite.com/admin不起作用

当我下载wordpress并手动安装它时,然后下载mysite。com/admin工作,打开管理面板。但是当我使用WP CLI /管理未重定向到管理面板。谁能帮我找到这个问题吗。使用命令如下:wp core download --allow-root wp core config --dbname=wp --dbuser=root --dbpass= --allow-root wp db create --allow-root wp core install --url=local