您现在的位置是:wordpress博征途国际下载官方正版客纯代码去掉分类目录Category加拿大PC28网站入口 >>正文
wordpress博征途国际下载官方正版客纯代码去掉分类目录Category加拿大PC28网站入口
六神无主网92人已围观
简介但安装过多插件对wordpress网站加载很不友好。将下面代码添加到你当前用的wordpess主题的functions.php 文件中保存即可://WordPress免插件去除分类categoryif...
但安装过多插件对wordpress网站加载很不友好。将下面代码添加到你当前用的wordpess主题的functions.php 文件中保存即可:
//WordPress免插件去除分类categoryif (git_get_option('git_category_b')) {add_action('load-themes.php', 'no_category_base_refresh_rules');add_action('created_category', 'no_category_base_refresh_rules');add_action('edited_category', 'no_category_base_refresh_rules');add_action('delete_category', 'no_category_base_refresh_rules');}function no_category_base_refresh_rules() {global $wp_rewrite;$wp_rewrite->flush_rules();}// Remove category baseadd_action('init', 'no_category_base_permastruct');function no_category_base_permastruct() {global $wp_rewrite, $wp_version;if (version_compare($wp_version, '3.4', '<')) {} else }// Add our custom category rewrite rulesadd_filter('category_rewrite_rules', 'no_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|rdf|rss|rss2|atom)/?$'] = 'index.php?category_name=$matches[1]&feed=$matches[2]';$category_rewrite['(' . $category_nicename . ')/page/?([0-9]{1,})/?$'] = 'index.php?category_name=$matches[1]&paged=$matches[2]';$category_rewrite['(' . $category_nicename . ')/?$'] = 'index.php?category_name=$matches[1]';}// Redirect support from Old Category Baseglobal $wp_rewrite;$old_category_base = get_option('category_base') ? get_option('category_base') : 'category';$old_category_base = trim($old_category_base, '/');$category_rewrite[$old_category_base . '/(.*)$'] = 'index.php?category_redirect=$matches[1]';//var_dump($category_rewrite); // For Debuggingreturn $category_rewrite;}// Add 'category_redirect' query variableadd_filter('query_vars', 'no_category_base_query_vars');function no_category_base_query_vars($public_query_vars) // Redirect if 'category_redirect' is setadd_filter('request', 'no_category_base_request');function no_category_base_request($query_vars) {//print_r($query_vars); // For Debuggingif (isset($query_vars['category_redirect'])) return $query_vars;}
保存后,可以通过不用插件来实现WordPress去掉分类链接中category目录,链接目录太深对搜索引擎蜘蛛抓取不太好,网上也出现了各种去除category目录的类似插件,比如WP No category Base 插件。即 如何免插件实现WordPress网站去掉分类链接中category目录?折腾WordPress的朋友都知道在分类链接中会出现一个/category/目录,你打开目录链接时有可能显示404等打不开情况。 以上就是WordPress纯代码去掉分类目录前缀URL链接中自带category的方法。
Tags:
相关文章
wordpress主题导航菜单添加小图标
wordpress博征途国际下载官方正版客纯代码去掉分类目录Category加拿大PC28网站入口wordpress头部导航添加图标字体的方法很多,最常见的是要安装插件。wordpress主题后台安装过插件会变的很卡,这里介绍WordPress主题导航菜单添加个性图标字体方法(适合一些响应式设计的...
阅读更多
大旗发帖助手下载/使用教程
wordpress博征途国际下载官方正版客纯代码去掉分类目录Category加拿大PC28网站入口大旗发帖助手是一个多次粘贴复制工具,能够快速粘贴文本的编辑发帖助手,软件功能强大,可以多个自定义快捷键,能够自定义黏贴内容,当你每天重复大量相同文本录入的时候本软件可以减轻你的负担,让你快捷的输入文本...
阅读更多
JavaScript时间与日期(Date类型)
wordpress博征途国际下载官方正版客纯代码去掉分类目录Category加拿大PC28网站入口ECMAScript提供了Date类型来处理时间和日期。Date类型内置一系列获取和设置日期时间信息的方法。一、Date类型ECMAScript中的Date类型是在早期Java 中 java.util...
阅读更多