我必须将旧的 noneWordpress 网站转换为 Wordpress 网站。 问题在于网址/永久链接。 旧网站的 url 结构为域名/页面/新闻/类别/新闻,用于新闻列表(存档)页面。对于单页 - 域名/新闻/%post-name%/ 没有类别。 所有者要求创建为 CPT。我还需要创建其他 CPT (5)。
Functions.php
function myfunction_custom_fields(){
$args = array(
'labels' => array(
'name' => 'News',
'singular_name' => 'News'
),
'has_archive' => true,
'hierarchical' => true,
'public' => true,
'supports' => array('title', 'editor', 'thumbnail','excerpt'),
'show_in_rest' => true,
'menu_position' => 5,
'publicly_queryable' => true,
'capability_type' => 'post',
'rewrite' => array('slug' => 'Pages/News/Category/news'),
);
register_post_type('news', $args);
}
add_action('init', 'myfunction_custom_fields');
但在这种情况下,我的单个页面的 url 是这样的 - domain-name/Pages/News/Category/news/%post-name%/
应该是这样的 - domain-name/news/%post-name%/
和 archive-news.php - domain-name/Pages/News/Category/news
感谢任何帮助