ページ内目次

任意のURLで、投稿アーカイブを表示する

意外とハマりました。

単純な投稿のアーカイブページのパーマリンクってなに?

archive.php なんだから、http://abc.com/archive とか、http://abc.com/post とかで…

開かない(;´Д`)

 

本来は、そもそもトップページがアーカイブページなんで、http://abc.com でいいんだけど、トップページに特定の固定ページを割り振ってる場合って少なくないんですヨ。

そして、トップページがアーカイブページであるが故に、デフォルトでは投稿記事のアーカイブ設定が無効なんですって。

 

なんですって?!

そこで、こうします。

finction.php です。

/* 投稿アーカイブの設定 */
function post_archive_origin( $args, $post_type ) {

	if ( 'post' == $post_type ) {
		$args['rewrite'] = true;
		$args['has_archive'] = 'column'; //任意のスラッグ名
	}
	return $args;

}
add_filter( 'register_post_type_args', 'post_archive_origin', 10, 2 );

これで、http://abc.com/column でアーカイブが表示できる。

おつ

This website stores cookies on your computer. These cookies are used to provide a more personalized experience and to track your whereabouts around our website in compliance with the European General Data Protection Regulation. If you decide to to opt-out of any future tracking, a cookie will be setup in your browser to remember this choice for one year.

Accept or Deny

↑上へまいりま〜す