Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/298.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在Wordpress中更改自定义帖子类型的单个帖子的URL_Php_Wordpress - Fatal编程技术网

Php 如何在Wordpress中更改自定义帖子类型的单个帖子的URL

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'

我已经在wordpress中创建了自定义帖子类型
指南
。因此,我可以在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');
    });