0
カテゴリ内のすべての投稿を表示する際に問題が発生しています。カテゴリ内のすべての投稿を表示できません - Wordpress
私はそうのように、のfunctions.phpにそれで行くことにカスタムポストとカテゴリを作成している:私はあなたがカテゴリをクリックすることができます期待してすべてのカテゴリを表示するためのテンプレートを作成している
function create_posttype() {
register_post_type('tours',
// CPT Options
array(
'labels' => array(
'name' => __('Tours'),
'singular_name' => __('Tour')
),
'public' => true,
//'has_archive' => true,
'rewrite' => array('slug' => 'tours'),
//'taxonomies' => array('category'), //A added
'hierarchical' => true //A added
)
);
}
// Hooking up our function to theme setup
add_action('init', 'create_posttype');
function my_taxonomies_tours() {
$labels = array(
'name' => _x('Tour Categories', 'taxonomy general name'),
'singular_name' => _x('Tour Category', 'taxonomy singular name'),
'search_items' => __('Search Tour Categories'),
'all_items' => __('All Tour Categories'),
'parent_item' => __('Parent Tour Category'),
'parent_item_colon' => __('Parent Tour Category:'),
'edit_item' => __('Edit Tour Category'),
'update_item' => __('Update Tour Category'),
'add_new_item' => __('Add New Tour Category'),
'new_item_name' => __('New Tour Category'),
'menu_name' => __('Tour Categories'),
);
$args = array(
'labels' => $labels,
'hierarchical' => true,
);
register_taxonomy('tour_category', 'tours', $args);
}
add_action('init', 'my_taxonomies_tours', 0);
すべての投稿を一覧表示します。私のテンプレートでは、私は次のようにあります
$custom_terms = get_terms('tour_category');
foreach($custom_terms as $custom_term) {
wp_reset_query();
$args = array('post_type' => 'tours',
'tax_query' => array(
array(
'taxonomy' => 'tour_category',
'field' => 'slug',
'terms' => $custom_term->slug,
),
),
);
$loop = new WP_Query($args);
if($loop->have_posts()) {
echo '<h2>'.$custom_term->name.'</h2>';
}
}
私は現在、カテゴリを示しているが、私はあなたがその特定のカテゴリ内のすべての投稿を表示できるように、このような方法でそれをリンクする方法がわからない何を。どんな助けでも大歓迎です。
$args = array('post_type' => 'tours',
'tax_query' => array(
array(
'taxonomy' => 'tour_category',
'field' => 'slug',
'terms' => $custom_term->slug,
),
),
'posts_per_page' => -1,
);
は、そうでない場合は、ページ値ごとに、デフォルトのポストを使用します(posts_per_pageを追加)このようなあなたの$ argsを変数を調整してみてください