【发布时间】:2017-02-27 17:02:58
【问题描述】:
我为 E.G. 添加了自定义帖子类型。电影并注册自定义分类。
我正在通过在帖子类型 slug 之前添加自定义分类名称来重写 slug。
我在注册帖子类型中添加了重写参数:
'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 )
);
我还在初始化操作中添加了以下行:
add_rewrite_rule( '^movies/(.*)/(.*)/([^/]+)/?$','index.php?type=$matches[2]', 'top' );
对于“post_type_link”操作:
// 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 );
}
现在我的网址是http://yourdomain.com/movie/fun/movie_name。
但是,问题是当我查看该帖子时,它称为archive.php而不是single.php,并且还像存档页面一样执行并显示所有页面。
请提供一些解决方案。接受任何建议。
谢谢
【问题讨论】:
-
我已经打印了每个链接的永久链接,它提供了完美的永久链接,例如:
http://yourdomain.com/movie/fun/moviename,但是当我访问它时,它会打开存档页面。
标签: php wordpress url-rewriting slug