【发布时间】:2019-02-22 04:53:51
【问题描述】:
我在我的 WordPress 应用程序中创建了一个自定义帖子类型,我希望它的 URL 通过连字符分隔。例如,自定义帖子的名称是Singh Across The World,URL 中为singhacrosstheworld,并希望它是singh-across-the-world。
我尝试使用singh-across-the-world / singh_across_the_world 而不是singhAcrossTheWorld 作为第一个参数,但它不起作用。
代码如下,请看:
register_post_type("singhAcrossTheWorld", [
"capability_type" => "post",
"description" => "Holds our Singh's specific data",
"public" => true,
"menu_position" => 6,
"has_archive" => true,
"show_admin_column" => true,
"supports" => [
"title",
"editor",
"thumbnail",
"excerpt",
"revisions",
"comments",
"custom-fields",
"page-attributes"
],
"taxonomies" => [
"post_tag"
],
"labels" => [
"name" => "Singh across the world",
"singular_name" => "Singh across the world",
"add_new" => "Add Singh",
"add_new_item" => "Add Singh",
"edit_item" => "Edit Singh",
"new_item" => "New Singh",
"all_items" => "All Singhs",
"view_item" => "View Singh",
"search_items" => "Search Singhs",
"not_found" => "No Singhs found",
"not_found_in_trash" => "No Singhs found in the Trash",
"parent_item_colon" => "",
"menu_name" => "S. A. T. W."
]
]);
【问题讨论】:
-
here-ya-go-m8 :
'rewrite' => array( 'slug' => 'singh-across-the-world' ),- 把它扔进你的register_post_type() -
记得在之后刷新你的永久链接
-
您在语义上可能会更好地为此使用分类术语或类别。例如,将帖子类型更改为名称,并在类别下添加分类术语“singh”。只是一个想法!
-
最初我是使用分类开发的,但客户希望在左侧菜单中有一个单独的部分,因此我必须将其更改为自定义帖子。
-
谢谢@Stender,它成功了:)