Created
November 8, 2014 02:13
-
-
Save tkc49/881ad66446c51dc7d226 to your computer and use it in GitHub Desktop.
RewriteAPIのサンプルソースです。 【管理画面】→【表示設定】→投稿ページ:ブログ(slug:blog)にした時に本来、URLが http://xxxx/blog となるのを http://xxxx/contents-list/reading/blog で投稿一覧を表示するサンプルです。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function myposttype_rewrite() { | |
global $wp_rewrite; | |
add_rewrite_rule( | |
'contents-list/reading/blog', | |
'index.php?pagename=blog', | |
'top' | |
); | |
} | |
add_action('init', 'myposttype_rewrite'); | |
function my_page_link($post_link, $id = 0, $leavename) { | |
global $wp_rewrite; | |
$post = get_post($id); | |
if ( is_wp_error( $post ) ) | |
return $post; | |
$blog = get_option( 'page_for_posts' ); | |
if( $id == $blog ){ | |
// http://xxxx/blog を http://xxxx/contens-list/reading/blog に置換する処理 | |
} | |
return $post_link; | |
} | |
add_filter('page_link', 'my_page_link', 1, 3); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment