为什么我对分类术语页面的点击会出现404错误?
我有分类“源”,通过插件在代码中注册。。。
<?php
/**
* Plugin Name: Context Taxonomy for Sources
* Description: Register custom taxonomy for sources.
* Version: 1.0.0
* Author: Robert Andrews
*/
/**
* ==============================================================================
* REGISTER TAXONOMY
* ==============================================================================
*/
if ( ! function_exists( \'register_taxonomy_source\' ) ) {
function register_taxonomy_source() {
$labels = array(
\'name\' => _x( \'Sources\', \'Taxonomy General Name\', \'text_domain\' ),
\'singular_name\' => _x( \'Source\', \'Taxonomy Singular Name\', \'text_domain\' ),
\'menu_name\' => __( \'Sources\', \'text_domain\' ),
\'all_items\' => __( \'All Sources\', \'text_domain\' ),
\'parent_item\' => __( \'Parent Source\', \'text_domain\' ),
\'parent_item_colon\' => __( \'Parent Source:\', \'text_domain\' ),
\'new_item_name\' => __( \'New Source Name\', \'text_domain\' ),
\'add_new_item\' => __( \'Add New Source\', \'text_domain\' ),
\'edit_item\' => __( \'Edit Source\', \'text_domain\' ),
\'update_item\' => __( \'Update Source\', \'text_domain\' ),
\'view_item\' => __( \'View Source\', \'text_domain\' ),
\'separate_items_with_commas\' => __( \'Separate Sources with commas\', \'text_domain\' ),
\'add_or_remove_items\' => __( \'Add or remove Source\', \'text_domain\' ),
\'choose_from_most_used\' => __( \'Choose from the most used\', \'text_domain\' ),
\'popular_items\' => __( \'Popular Source\', \'text_domain\' ),
\'search_items\' => __( \'Search Source\', \'text_domain\' ),
\'not_found\' => __( \'Not Found\', \'text_domain\' ),
\'no_terms\' => __( \'No Source\', \'text_domain\' ),
\'items_list\' => __( \'Sources list\', \'text_domain\' ),
\'items_list_navigation\' => __( \'Sources list navigation\', \'text_domain\' ),
);
$rewrite = array(
\'slug\' => \'source\',
\'with_front\' => true,
\'hierarchical\' => false,
);
$args = array(
\'labels\' => $labels,
\'hierarchical\' => false,
\'public\' => true,
\'single_value\' => false, // Use single-select radio button, only one Source per object
\'show_ui\' => true,
\'show_admin_column\' => true,
\'show_in_nav_menus\' => true,
\'show_tagcloud\' => true,
\'rewrite\' => $rewrite,
);
register_taxonomy(
/* taxonomy name */ \'source\',
/* attach to object */ array( \'quote\',\'article\',\'report\',\'event\', \'post\' ),
/* arguments */ $args
);
}
add_action( \'init\', \'register_taxonomy_source\', 0 );
}
?>
分类法在后端工作。
现在我正在构建一个主题,我想看到这样的页面http://www.example.com/source/term-name 作品但事实并非如此。
我的包含htaccess文件。。。
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\\.php$ - [L]
# add a trailing slash to /wp-admin
RewriteRule ^wp-admin$ wp-admin/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^(wp-(content|admin|includes).*) $1 [L]
RewriteRule ^(.*\\.php)$ $1 [L]
RewriteRule . index.php [L]
</IfModule>
# END WordPress
# Modified for Multisite https://www.namecheap.com/support/knowledgebase/article.aspx/9191/29/how-to-create-a-wildcard-subdomain-in-cpanel
# Previous here:
# RewriteEngine On
# RewriteBase /
# RewriteRule ^index\\.php$ - [L]
# RewriteCond %{REQUEST_FILENAME} !-f
# RewriteCond %{REQUEST_FILENAME} !-d
# RewriteRule . /index.php [L]
我刚刚拆下了那些部件。在此之前,404/source/term name页面实际上被重定向到主页。
我有。。。
删除了上述内容。htaccess部分
单击永久链接页面上的保存添加flush_rewrite_rules()
与我的代码类似仍然是404。我不明白。有一件有趣的事要注意。。。在后端我的“源”分类列表中,当您打开带有视图链接的分类术语页面时,我只看到每个网站的URL如下http://www.example.com/blog/source/term-name - 不http://www.example.com/source/term-name. 应该是后者。然而,这两种变体都失败了404。
在我的Permalinks设置页面上,“Common Settings”设置为“Custom Structure”:/blog/%year%/%monthnum%/%day%/%postname%/这可能是“blog”的来源,但我仍然不理解404。
我刚刚删除了“/博客/”。现在URL是http://www.example.com/source/term-name - 但是,这仍然是404。