最近的項(xiàng)目使用到了這個(gè)插件,主要是為WP提供一個(gè)wiki百科功能,插件是收費(fèi)的:傳送門.
遇到的問題是固定地址使用的是/%postname%/的方式,中文標(biāo)題對(duì)百度搜錄不利,所以想辦法要把結(jié)構(gòu)變成/%post_id%.html,所以就找了一些教程寫了一個(gè)規(guī)則,可以把固定連接改成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就起作用了~
新聞熱點(diǎn)
疑難解答
圖片精選