カスタム投稿タイプのアーカイブページの作り方について
-
お世話になります。
最近、カスタム投稿を使ったサイトを作っていますが、アーカイブページ(またはカテゴリーページ)がうまく表示できません。
トップページにカスタム投稿の新着一覧を表示して、パーマリンクでシングルページを表示するところまではできたのですが、シングルページサイドバーに記述したカスタム投稿カテゴリーをクリックして、アーカイブページを表示することが、どうしてもできません。
index.phpが読まれてしまいます。カスタム投稿はプラグインを使わず、function.phpに記述しました。
カスタム投稿名:estate
カスタム投稿カテゴリー名:estate-cat
カテゴリー:
tochi
tatemono
用意したファイル:
archive-estate.php
single-estate.php
サイドバーの記述
<?php wp_list_categories(‘title_li=&taxonomy=estate-cat’); ?>です。
シングルページのパーマリンクは、http://webアドレス/estate/329.html/(記事ID)で表示できています。
カテゴリーのパーマリンクは、http://webアドレス/estate-cat/tochi/となってしまい。index.phpが読まれてしまいます。
http://webアドレス/estate/とアドレスを入力すると、アーカイブページは表示されますが、http://webアドレス/estate/tochi/と入力してもカテゴリーごとには表示してくれません。// カスタム投稿タイプを定義
add_action( ‘init’, ‘register_cpt_estate’ );function register_cpt_estate() {
$labels = array(
‘name’ => _x( ‘物件情報’, ‘estate’ ),
‘singular_name’ => _x( ‘物件情報’, ‘estate’ ),
‘add_new’ => _x( ‘新規追加’, ‘estate’ ),
‘add_new_item’ => _x( ‘新しい物件情報を追加’, ‘estate’ ),
‘edit_item’ => _x( ‘物件情報を編集’, ‘estate’ ),
‘new_item’ => _x( ‘新しい物件情報’, ‘estate’ ),
‘view_item’ => _x( ‘物件情報を見る’, ‘estate’ ),
‘search_items’ => _x( ‘物件情報検索’, ‘estate’ ),
‘not_found’ => _x( ‘物件情報が見つかりません’, ‘estate’ ),
‘not_found_in_trash’ => _x( ‘ゴミ箱に物件情報はありません’, ‘estate’ ),
‘parent_item_colon’ => _x( ‘親物件情報:’, ‘estate’ ),
‘menu_name’ => _x( ‘物件情報’, ‘estate’ ),
);$args = array(
‘labels’ => $labels,
‘hierarchical’ => true,
‘description’ => ‘物件情報’,
‘supports’ => array( ‘title’, ‘editor’, ‘excerpt’, ‘thumbnail’, ‘custom-fields’ ),‘public’ => true,
‘show_ui’ => true,
‘show_in_menu’ => true,
‘show_in_nav_menus’ => true,
‘publicly_queryable’ => true,
‘exclude_from_search’ => false,
‘has_archive’ => true,
‘query_var’ => true,
‘can_export’ => true,
‘capability_type’ => ‘post’
);
register_post_type( ‘estate’, $args );
}// カスタム投稿タイプのパーマリンクをIDに変更
add_action(‘init’, ‘myposttype_rewrite’);
function myposttype_rewrite() {
global $wp_rewrite;$queryarg = ‘post_type=estate&p=’;
$wp_rewrite->add_rewrite_tag(‘%estate_id%’, ‘([^/]+)’,$queryarg);
$wp_rewrite->add_permastruct(‘estate’, ‘/estate/%estate_id%.html’, false);}
add_filter(‘post_type_link’, ‘myposttype_permalink’, 1, 3);
function myposttype_permalink($post_link, $id = 0, $leavename) {
global $wp_rewrite;
$post = &get_post($id);
if ( is_wp_error( $post ) )
return $post;
$newlink = $wp_rewrite->get_extra_permastruct($post->post_type);
$newlink = str_replace(‘%’.$post->post_type.’_id%’, $post->ID, $newlink);
$newlink = home_url(user_trailingslashit($newlink));
return $newlink;
}//カスタムタクソノミー、カテゴリタイプ
register_taxonomy(
‘estate-cat’,
‘estate’,
array(
‘hierarchical’ => true,
‘update_count_callback’ => ‘_update_post_term_count’,
‘label’ => ‘物件のカテゴリー’,
‘singular_label’ => ‘物件のカテゴリー’,
‘public’ => true,
‘show_ui’ => true
)
);宜しくお願い致します。
- トピック「カスタム投稿タイプのアーカイブページの作り方について」には新たに返信することはできません。