600字范文,内容丰富有趣,生活中的好帮手!
600字范文 > 无需实现插件WordPress在分类链接中category (亲测有效)

无需实现插件WordPress在分类链接中category (亲测有效)

时间:2019-08-22 06:13:20

相关推荐

无需实现插件WordPress在分类链接中category (亲测有效)

使用wordpress建网站的时候,我们知道修改固定链接做伪静态后,分类链接中会出现一个/category/目录。

在分类链接中category目录,网上出现了各种去除category目录的wordpress插件,比如WP No category Base插件。还有固定链接中的插件。category写英文句号去掉category方法。这种方法总觉得奇怪,不推荐。

不喜欢用wordpress对于插件站,可以使用代码,尽量不要使用插件。今天,我将讨论如何在没有插件的情况下实现它WordPress在分类链接中category目录。

在分类链接中category方法

复制下面我们提供的代码,粘贴到您网站使用的主题模板函数文件 functions.php 可以在文件中:

///去除分类标志代码add_action( load-themes.php, o_category_base_refresh_rules);add_action(created_category, o_category_base_refresh_rules);add_action(edited_category, o_category_base_refresh_rules);add_action(delete_category, o_category_base_refresh_rules);function no_category_base_refresh_rules() { global $wp_rewrite; $wp_rewrite -> flush_rules() register_deactivation_hook(__FILE__, o_category_base_deactivate);// function no_category_base_deactivate() {// remove_filter(category_rewrite_rules, o_category_base_rewrite_rules);// // We don want to insert our custom rules again// no_category_base_refresh_rules();// }// Remove category baseadd_action(init, o_category_base_permastruct);function no_category_base_permastruct() { global $wp_rewrite, $wp_version; if (version_compare($wp_version, 3.4, extra_permastructs[category][0] = �tegory%; } else { $wp_rewrite -> extra_permastructs[category][struct] = �tegory%; }}// Add our custom category rewrite rulesadd_filter(category_rewrite_rules, o_category_base_rewrite_rules);function no_category_base_rewrite_rules($category_rewrite) { //var_dump($category_rewrite); // For Debugging $category_rewrite = array(); $categories = get_categories(array(hide_empty => false)); foreach ($categories as $category) { $category_nicename = $category -> slug; if ($category -> parent == $category -> cat_ID)// recursive recursion $category -> parent = 0; elseif ($category -> parent != 0) $category_nicename = get_category_parents($category -> parent, false, /, true) . $category_nicename; $category_rewrite[( . $category_nicename . )/(?:feed/)?:feed/)?(feed

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。