最近的项目使用到了这个插件,主要是为WP提供一个wiki百科功能,插件是收费的:传送门.
遇到的问题是固定地址使用的是/%postname%/的方式,中文标题对百度搜录不利,所以想办法要把结构变成/%post_id%.html,所以就找了一些教程写了一个规则,可以把固定连接改成wiki/post id.html的方式:
- add_filter('post_type_link', 'custom_wiki_link', 1, 3);
- function custom_wiki_link( $link, $post = 0 ){
- if ( $post->post_type == 'incsub_wiki' ){
- return home_url( 'wiki/' . $post->ID .'.html' );
- } else {
- return $link;
- }
- }
- add_action( 'init', 'custom_wiki_rewrites_init' );
- function custom_wiki_rewrites_init(){
- add_rewrite_rule( //Vevb.com
- 'wiki/([0-9]+)?.html$',
- 'index.php?post_type=incsub_wiki&p=$matches[1]',
- 'top' );
- }
加入functions就起作用了~
新闻热点
疑难解答
图片精选