カスタム投稿で年別アーカイブをプルダウンで表示したい
-
どうもお世話になります。
カスタム投稿で記事をつくり、年別アーカイブをプルダウンで表示したいのですが、
年数を選択後のURLの語尾が
www,hogehoge.com/date/2012?post_type=activity となってほしいところが
www,hogehoge.com/date/2012 となり、デフォルトの投稿のアーカイブが表示されてしまい困っています。function.php に
global $my_archives_post_type; add_filter( 'getarchives_where', 'my_getarchives_where', 10, 2 ); function my_getarchives_where( $where, $r ) { global $my_archives_post_type; if ( isset($r['post_type']) ) { $my_archives_post_type = $r['post_type']; $where = str_replace( '\'post\'', '\'' . $r['post_type'] . '\'', $where ); } else { $my_archives_post_type = ''; } return $where; } add_filter( 'get_archives_link', 'my_get_archives_link' ); function my_get_archives_link( $link_html ) { global $my_archives_post_type; if ( '' != $my_archives_post_type ) $add_link .= '?post_type=' . $my_archives_post_type; $link_html = preg_replace("/href=\'(.+)\'\s/","href='$1".$add_link."'",$link_html); return $link_html; }
上記の内容を挿入して
wp_get_archives('show_post_count=1&type=yearly&post_type=activity');
でリスト表示したものは、リンク先がこちらの望むURL(www,hogehoge.com/date/2012?post_type=activity)で出力されます。
<select name="archive-dropdown" onChange='document.location.href=this.options[this.selectedIndex].value;'><option value=""><?php echo attribute_escape(__('過去の情報を探す')); ?></option> <?php wp_get_archives('show_post_count=1&type=yearly&post_type=news'); ?> </select>
上記の書き方で、プルダウン表示した場合のリンクURLの語尾が、www,hogehoge.com/date/2012 となってしまいます。
何か方法はありますでしょうか?
よろしくお願いします。
3件の返信を表示中 - 1 - 3件目 (全3件中)
3件の返信を表示中 - 1 - 3件目 (全3件中)
- トピック「カスタム投稿で年別アーカイブをプルダウンで表示したい」には新たに返信することはできません。