カスタム投稿タイプでarchive-カスタム投稿.phpが使用できない
-
現在、カスタム投稿を使用してWP構築しております。
●●.com/gallery/
ではarchive-gallery.phpが適用されますが、●●.com/gallery/gallery_category/medium
ではarchive-gallery.phpが適用されずindex.phpが適用されてしまいます。
なお、taxnomy-gallery_category.phpを作成してもindex.phpが適用されてしまいます。どのような設定をすればarchive-gallery.phpで表示されるのでしょうか?
functions.phpは下記のように書いています。どなたかお分かりになる方がいらっしゃいましたら、ご教授の程宜しくお願いします。
■functions.php
/* ■■■ カスタム投稿タイプ[gallery] ■■■ */
function gallery_custom_post_type() {
$labels = array(
‘name’ => _x(‘ギャラリー’, ‘post type general name’),
‘singular_name’ => _x(‘ギャラリー’, ‘post type singular name’),
‘add_new’ => _x(‘ギャラリーを追加’, ‘gallery’),
‘add_new_item’ => __(‘新しいギャラリーを追加’),
‘edit_item’ => __(‘ギャラリーを編集’),
‘new_item’ => __(‘新しいギャラリー’),
‘view_item’ => __(‘ギャラリーを見る’),
‘search_items’ => __(‘記事を探す’),
‘not_found’ => __(‘記事はありません’),
‘not_found_in_trash’ => __(‘ゴミ箱に記事はありません’),
‘parent_item_colon’ => ”
);
$args = array(
‘labels’ => $labels,
‘public’ => true,
‘publicly_queryable’ => true,
‘show_ui’ => true,
‘query_var’ => true,
‘rewrite’ => true,
‘capability_type’ => ‘post’,
‘hierarchical’ => false,
‘menu_position’ => 5,
‘has_archive’ => true,
‘supports’ => array(‘title’,’editor’,’author’,’excerpt’,’thumbnail’,’comments’),
‘taxonomies’ => array(‘gallery_category’,’gallery_tag’)
);
register_post_type(‘gallery’,$args);
// カスタムタクソノミーを作成
//カテゴリータイプ
$args = array(
‘label’ => ‘カテゴリを追加’,
‘public’ => true,
‘show_ui’ => true,
‘hierarchical’ => true
);
register_taxonomy(‘gallery_category’,’gallery’,$args);
//タグタイプ
$args = array(
‘label’ => ‘タグを追加’,
‘public’ => true,
‘show_ui’ => true,
‘hierarchical’ => false
);
register_taxonomy(‘gallery_tag’,’gallery’,$args);
}
add_action(‘init’, ‘gallery_custom_post_type’);/* ■■■ カスタム投稿タイプ[staff] ■■■ */
function staff_custom_post_type() {
$labels = array(
‘name’ => _x(‘スタッフ’, ‘post type general name’),
‘singular_name’ => _x(‘スタッフ’, ‘post type singular name’),
‘add_new’ => _x(‘スタッフを追加’, ‘staff’),
‘add_new_item’ => __(‘新しいスタッフを追加’),
‘edit_item’ => __(‘スタッフを編集’),
‘new_item’ => __(‘新しいスタッフ’),
‘view_item’ => __(‘スタッフを見る’),
‘search_items’ => __(‘記事を探す’),
‘not_found’ => __(‘記事はありません’),
‘not_found_in_trash’ => __(‘ゴミ箱に記事はありません’),
‘parent_item_colon’ => ”
);
$args = array(
‘labels’ => $labels,
‘public’ => true,
‘publicly_queryable’ => true,
‘show_ui’ => true,
‘query_var’ => true,
‘rewrite’ => true,
‘capability_type’ => ‘post’,
‘hierarchical’ => false,
‘menu_position’ => 5,
‘has_archive’ => true,
‘supports’ => array(‘title’,’editor’,’author’,’excerpt’,’thumbnail’,’comments’),
‘taxonomies’ => array(‘staff_category’,’staff_tag’)
);
register_post_type(‘staff’,$args);
// カスタムタクソノミーを作成
//カテゴリータイプ
$args = array(
‘label’ => ‘カテゴリを追加’,
‘public’ => true,
‘show_ui’ => true,
‘hierarchical’ => true
);
register_taxonomy(‘staff_category’,’staff’,$args);
//タグタイプ
$args = array(
‘label’ => ‘タグを追加’,
‘public’ => true,
‘show_ui’ => true,
‘hierarchical’ => false
);
register_taxonomy(‘staff_tag’,’staff’,$args);
}
add_action(‘init’, ‘staff_custom_post_type’);/* ■■■ カスタム投稿タイプ[共通] ■■■ */
function my_custom_post_type_archive_where( $where, $args ){
$post_type = isset( $args[‘post_type’] ) ? $args[‘post_type’] : ‘post’;
$where = “WHERE post_type = ‘$post_type’ AND post_status = ‘publish'”;
return $where;
}
add_filter( ‘getarchives_where’, ‘my_custom_post_type_archive_where’, 10, 2 );
- トピック「カスタム投稿タイプでarchive-カスタム投稿.phpが使用できない」には新たに返信することはできません。