重写slug,添加分类名称call archive.php而不是single.php WordPress

重写slug,添加分类名称call archive.php而不是single.php WordPress,php,wordpress,url-rewriting,slug,Php,Wordpress,Url Rewriting,Slug,我已经为例如电影添加了自定义帖子类型,还注册了自定义分类法 我通过在post类型slug之前添加自定义分类名称来重写slug 我在寄存器post类型中添加了rewrite参数: 'rewrite' => array( 'slug' => 'movie/%tax_name%', 'with_front' => false ) 以及下面的分类参数: array( 'labels' => $lables, 'show_ui'

我已经为例如电影添加了自定义帖子类型,还注册了自定义分类法

我通过在post类型slug之前添加自定义分类名称来重写slug

我在寄存器post类型中添加了rewrite参数:

'rewrite' => array( 'slug' => 'movie/%tax_name%', 'with_front' => false )
以及下面的分类参数:

array(
    'labels'            => $lables,
    'show_ui'           => true,
    'show_admin_column' => true,
    'query_var'         => true,
    'hierarchical'      => true,
    'has_archive'       => false,
    'rewrite'           => array( 'slug' => 'type', 'with_front' => false )
);
我还为init操作添加了以下行:

add_rewrite_rule( '^movies/(.*)/(.*)/([^/]+)/?$','index.php?type=$matches[2]', 'top' );
对于“后链接类型”操作:

// Add parent taxonomy name / module name
$terms = wp_get_post_terms( $post->ID, 'type', array() );
$term = isset($terms['0']) ? $terms['0'] : '';
if( !empty($term->slug) ) {
    $link = str_replace( '%tax_name%', $term->slug, $link );
} else {
    $link = str_replace( '/%tax_name%', '', $link );
}
现在我的网址是

我从这里得到了一些参考:

但是,问题是,当我查看那篇文章时,它被称为archive.php,而不是single.php,并且执行类似于归档页面的操作并显示所有页面

请提供一些解决方案。接受任何建议


谢谢

自我研发后我得到了答案,我需要改变:

add_rewrite_rule( '^movies/(.*)/(.*)/([^/]+)/?$','index.php?type=$matches[2]', 'top' );
致:


自我研发后我得到了答案,我需要改变:

add_rewrite_rule( '^movies/(.*)/(.*)/([^/]+)/?$','index.php?type=$matches[2]', 'top' );
致:


我已经打印了每个链接的永久链接,这是一个完美的永久链接,如:
http://yourdomain.com/movie/fun/moviename
,但当我访问它时,它会打开归档页面。我已经打印了每个链接的永久链接,它提供了完美的永久链接,如:
http://yourdomain.com/movie/fun/moviename
,但当我访问它时,它会打开归档页面。