我将此代码用于自定义post类型calles公文包。现在我想在项目之间使用父子关系。例如,我有一个URL为www.domain的公文包项目。de/portfolio-item1
另一个公文包项目应该是公文包项目1的子项目,url应该是www.domain。de/portfolio-item1/portfolio-item2
我是一个php初学者,我不知道如何才能实现这一点。谁能帮帮我吗?
// Portfolio Post Type
add_action(\'init\',\'wpthesis_create_portfolio_init\');
function wpthesis_create_portfolio_init() {
$labels = array
( \'name\' => _x(\'Portfolio\', \'post type general name\'),
\'singular_name\' => _x(\'item\', \'post type singular name\'),
\'add_new\' => _x(\'Add New\', \'Portfolio Item\'),
\'add_new_item\' => __(\'Add New Portfolio Item\'),
\'edit_item\' => __(\'Edit Portfolio Item\'),
\'new_item\' => __(\'New Portfolio Item\'),
\'view_item\' => __(\'View Portfolio Item\'),
\'search_items\' => __(\'Search Portfolio\'),
\'not_found\' => __(\'No portfolio items found\'),
\'not_found_in_trash\' => __(\'No portfolio items found in Trash\'),
\'parent_item_colon\' => \'\'
);
$support = array
(
\'title\',
\'editor\',
\'author\',
\'thumbnail\',
\'custom-fields\',
\'comments\',
\'genesis-seo\',
\'genesis-layouts\',
\'revisions\'
);
$args = array
(
\'labels\' => $labels,
\'public\' => TRUE,
\'rewrite\' => array(\'slug\'=>(\'produkte-leistungen\'),\'with_front\'=>false),
\'capability_type\' => \'page\',
\'hierarchical\' => FALSE,
\'query_var\' => true,
\'supports\' => $support, \'taxonomies\' => array(\'portfolio-category\'),
\'menu_position\' => 5
);
register_post_type(\'portfolio\',$args);
register_taxonomy(
\'portfolio-category\',
\'portfolio\',
array(
\'hierarchical\' => TRUE,
\'label\' => \'Categories\',
\'query_var\' => TRUE,
\'rewrite\' => FALSE,
)
);
}
最合适的回答,由SO网友:phatskat 整理而成
详细阐述Mayeenul Islam所说的话WP Docs on regsiter_post_type
hierarchical
(布尔)(可选)帖子类型是否为层次结构(例如页面)。Allows Parent to be specified. “supports”参数应包含“page attributes”,以在编辑器页面上显示父选择框。默认值:false
强调我的。将其设置为true后,您应该能够将这些帖子相互关联。
编辑:添加代码
$support = array (
\'title\',
\'editor\',
\'author\',
\'thumbnail\',
\'custom-fields\',
\'comments\',
\'genesis-seo\',
\'genesis-layouts\',
\'revisions\',
// Add this to supports
\'page-attributes\',
);
$args = array (
\'labels\' => $labels,
\'public\' => TRUE,
\'rewrite\' => array(\'slug\'=>(\'produkte-leistungen\'),\'with_front\'=>false),
\'capability_type\' => \'page\',
// You had this set to FALSE, try it with TRUE
\'hierarchical\' => TRUE,
\'query_var\' => true,
\'supports\' => $support,
\'taxonomies\' => array(\'portfolio-category\'),
\'menu_position\' => 5
);
register_post_type(\'portfolio\',$args);
在上面的代码片段中,我将“页面属性”添加到
$support
并将“分层”选项设置为
TRUE
在里面
$args
. 这应该会让你得到正确的设置。