比较熟悉的朋友应该知道,如果要修改文章(post)的固定链接结构(),可以到后台管理界面进行修改。例如,如果您希望页面地址具有“标签”前缀,格式为:
http://www.nbzhuti.cn/tag/108
您可以在后台的“永久链接”设置界面中将永久链接结构设置为“/news/%%”。
< p tag) 也变成了“/tag/%tag%”的样子。
现在的问题是,如果要自定义标签(tag)的固定链接,使其不随文章页面(post)链接结构的变化而变化,让标签页面(tag)有更个性化的链接结构,怎么做?
或者,我也想自定义分类页面的永久链接结构()wordpress页面 分类目录,怎么办?
我们应该从 $ 对象开始。前提是要知道$对象里面的数据结构是什么wordpress网站建设,才能知道怎么修改,所以把$打印出来了,下面是对象的内部结构:
WP_Rewrite Object
(
[permalink_structure] => /post/%postname%.html
[use_trailing_slashes] =>
[author_base] => author
[page_structure] => %pagename%.html
[search_base] => search
[comments_base] => comments
[pagination_base] => page
[comments_pagination_base] => comment-page
[feed_base] => feed
[front] => /post/
[root] =>
[index] => index.php
[matches] =>
[rules] =>
[extra_rules] => Array
(
)
[extra_rules_top] => Array
(
)
[non_wp_rules] => Array
(
)
[extra_permastructs] => Array
(
[category] => Array
(
[with_front] =>
[ep_mask] => 512
[paged] => 1
[feed] => 1
[forcomments] =>
[walk_dirs] => 1
[endpoints] => 1
[struct] => cat/%category%
)
[post_tag] => Array
(
[with_front] =>
[ep_mask] => 1024
[paged] => 1
[feed] => 1
[forcomments] =>
[walk_dirs] => 1
[endpoints] => 1
[struct] => tag/%post_tag%
)
[post_format] => Array
(
[with_front] => 1
[ep_mask] => 0
[paged] => 1
[feed] => 1
[forcomments] =>
[walk_dirs] => 1
[endpoints] => 1
[struct] => /post/type/%post_format%
)
)
[endpoints] => Array
(
)
[use_verbose_rules] =>
[use_verbose_page_rules] => 1
[rewritecode] => Array
(
[0] => %year%
[1] => %monthnum%
[2] => %day%
[3] => %hour%
[4] => %minute%
[5] => %second%
[6] => %postname%
[7] => %post_id%
[8] => %author%
[9] => %pagename%
[10] => %search%
[11] => %category%
[12] => %post_tag%
[13] => %post_format%
)
[rewritereplace] => Array
(
[0] => ([0-9]{4})
[1] => ([0-9]{1,2})
[2] => ([0-9]{1,2})
[3] => ([0-9]{1,2})
[4] => ([0-9]{1,2})
[5] => ([0-9]{1,2})
[6] => ([^/]+)
[7] => ([0-9]+)
[8] => ([^/]+)
[9] => ([^/]+?)
[10] => (.+)
[11] => (.+?)
[12] => ([^/]+)
[13] => ([^/]+)
)
[queryreplace] => Array
(
[0] => year=
[1] => monthnum=
[2] => day=
[3] => hour=
[4] => minute=
[5] => second=
[6] => name=
[7] => p=
[8] => author_name=
[9] => pagename=
[10] => s=
[11] => category_name=
[12] => tag=
[13] => post_format=
)
[feeds] => Array
(
[0] => feed
[1] => rdf
[2] => rss
[3] => rss2
[4] => atom
)
)
这个清楚了,之前我们修改页面(page)的结构被修改了[] => %%.htmlwordpress页面 分类目录,而标签页(tag)的结构明显被修改了[][][] => tag/%%,而修改分类页面的固定链接()自然会修改[][][]的值 => cat/%%。
以下是具体修改代码:
function custom_page_rules() {
global $wp_rewrite;
//修改page的固定链接结构
$wp_rewrite->page_structure = $wp_rewrite->root . 'post/%pagename%.html';
//修改tag的固定链接结构
$wp_rewrite->extra_permastructs['post_tag']['with_front'] = '';
$wp_rewrite->extra_permastructs['post_tag']['struct'] = 'tag/%post_tag%';
}
将上述代码放入主题核心文件.php中wordpress网站制作,自定义1)页面的结构和2)tag页面的结构。
修改分类页面的永久链接也是如此()。
文章来自互联网,侵权请联系删除,文章阐述观点来自文章出处,并不代表本站观点。
www.8001717.cn