我已经在一个Wordpress主题上工作了几个星期了,现在我面临着以下问题:我有一个自定义的帖子类型叫做"Guide",我使用了重写标签将其更改为" stappplan "。现在我想将其更改为"application",但重写不起作用。它甚至没有到达Archive.php文件,这很奇怪。我使用下面的代码来注册我的自定义帖子类型。
$guides = new KCContentType('Guide',
['rewrite' => ['slug' => 'application'],'menu_icon' => get_template_directory_uri().'/img/icons/application.svg','has_archive' => true],
['plural_name' => 'Applications']);
和一个helper类,如下所示:
<?php
namespace KC;
class ContentType {
public $type;
public $options = [];
public $labels = [];
/**
* Creates a new ContentType object
* @param string $type
* @param array $options
* @param array $labels
*/
public function __construct($type, $options = [], $labels = []) {
$this->type = $type;
$default_options = [
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'query_var' => true,
'rewrite' => ['slug' => strtolower($type)],
'capability_type' => 'page',
'has_archive' => true,
'hierarchical' => true,
'taxonomies' => ['post_tag','category'],
'supports' => ['title', 'editor', 'revisions', 'thumbnail','page-attributes','excerpt']
];
$required_labels = [
'singular_name' => ucwords($this->type),
'plural_name' => ucwords($this->type)
];
$this->options = $options + $default_options;
$this->labels = $labels + $required_labels;
$this->options['labels'] = $labels + $this->default_labels();
add_action('init', array($this, 'register'));
}
/**
* Registers the content type using WP core function(s)
* @return null
*/
public function register() {
register_post_type($this->type, $this->options);
}
/**
* Creates intelligent default labels from the required singular and plural labels
* @return array
*/
public function default_labels() {
return [
'name' => $this->labels['plural_name'],
'singular_name' => $this->labels['singular_name'],
'add_new' => 'Add New ' . $this->labels['singular_name'],
'add_new_item' => 'Add New ' . $this->labels['singular_name'],
'edit' => 'Edit',
'edit_item' => 'Edit ' . $this->labels['singular_name'],
'new_item' => 'New ' . $this->labels['singular_name'],
'view' => 'View ' . $this->labels['singular_name'] . ' Page',
'view_item' => 'View ' . $this->labels['singular_name'],
'search_items' => 'Search ' . $this->labels['plural_name'],
'not_found' => 'No matching ' . strtolower($this->labels['plural_name']) . ' found',
'not_found_in_trash' => 'No ' . strtolower($this->labels['plural_name']) . ' found in Trash',
'parent_item_colon' => 'Parent ' . $this->labels['singular_name']
];
}
}
希望这只是我的错,而不是Wordpress的问题。
我自己解决了这个问题,通过在wordpress cms中的设置->永久链接并将设置更改为另一个。完成此操作后保存它并重新引用页面。
在此之后更改它解决了我的问题!