如何为帖子启用父子关系和帖子属性管理小工具

时间:2013-03-04 作者:Tim Truston

我希望在创建新帖子时能够选择父帖子。我认为,让“页面属性”管理小部件也能同样适用于帖子应该很容易。该用例适用于此站点:thedevs.org 如果我想让人们发布项目,那么以后再发布新的项目帖子,这些帖子是项目帖子的子帖子,并将列在父帖子下。我对wordpress有点陌生,但我很容易使用php。一个有效的插件或代码片段会有所帮助。

3 个回复
SO网友:Chip Bennett

控制post类型层次结构的参数称为\'hierarchical\', 并在通过注册post类型时设置register_post_type(). WordPress核心注册\'post\' 具有的帖子类型\'hierarchical\' => false.

要覆盖此设置,refer to this question.

SO网友:Tim Truston

将此代码添加到我的。。神话元素/功能。php文件对我来说很有用:

            /* Register Custom Post Type for Projects*/
            add_action(\'init\', \'project_post_type_init\');
            function project_post_type_init() {
              $labels = array(
                \'name\' => _x(\'My Projects\', \'post type general name\'),
                \'singular_name\' => _x(\'Project\', \'post type singular name\'),
                \'add_new\' => _x(\'Add New\', \'Project\'),
                \'add_new_item\' => __(\'Add New Project\'),
                \'edit_item\' => __(\'Edit Project\'),
                \'new_item\' => __(\'New Project\'),
                \'view_item\' => __(\'View Project\'),
                \'search_items\' => __(\'Search Projects\'),
                \'not_found\' =>  __(\'No Projects found\'),
                \'not_found_in_trash\' => __(\'No Projects found in Trash\'),
                \'parent_item_colon\' => __(\'Post\'),
                \'parent\' => __(\'Post\'),
              );
              $args = array(
                \'labels\' => $labels,
                \'public\' => true,
                \'publicly_queryable\' => true,
                \'show_ui\' => true, //false - to hide from the admin area menu
                \'rewrite\' => true,
                \'query_var\' => true,
                \'capability_type\' => \'post\',
                \'hierarchical\' => true, //allow parent pages
                \'show_in_nav_menus\' => false,
                \'menu_position\' => 1000,
                \'supports\' => array( \'title\', \'editor\', \'author\', \'thumbnail\', \'excerpt\', \'comments\', \'page-attributes\')
              );
              register_post_type(\'project\',$args);
            }

SO网友:WPIndex

只需阅读以下文档并在函数中添加函数即可。phphttps://codex.wordpress.org/Function_Reference/add_post_type_support

结束

相关推荐