Php 如何在Wordpress中更改自定义帖子类型的单个帖子的URL
我已经在wordpress中创建了自定义帖子类型Php 如何在Wordpress中更改自定义帖子类型的单个帖子的URL,php,wordpress,Php,Wordpress,我已经在wordpress中创建了自定义帖子类型指南。因此,我可以在URL:http://example.com/guides/。当我点击查看任何指南文章的详细视图时,URL结构已被修改为http://example.com/guides/any-post-of-guide/。这里我只想:对于所有指南,url应该有指南,对于指南的单个帖子,url结构应该有指南(而不是指南)。你能告诉我怎么做吗 下面是我所做和尝试的代码: $args = array( 'labels'
指南
。因此,我可以在URL:http://example.com/guides/
。当我点击查看任何指南文章的详细视图时,URL结构已被修改为http://example.com/guides/any-post-of-guide/
。这里我只想:对于所有指南,url应该有指南,对于指南的单个帖子,url结构应该有指南(而不是指南)。你能告诉我怎么做吗
下面是我所做和尝试的代码:
$args = array(
'labels' => $labels,
'description' => __( 'Description.', 'your-plugin-textdomain' ),
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => 'ml-vault.php',
'query_var' => true,
'rewrite' => array( 'slug' => 'guides'),
'capability_type' => 'post',
'has_archive' => true,
'hierarchical' => false,
'menu_position' => null,
'supports' => array( 'title','editor', 'excerpt', 'thumbnail')
);
您是否重新考虑了args数组中的参数重写?更多关于重写的信息,请点击此处-
rewrite
参数更改为:'rewrite' => array('slug' => 'guide', 'with_front' => false),
add_action('init', function()
{
add_rewrite_rule('^guides/?$', 'index.php?post_type=guides', 'top');
});