I have a custom post type named cities. For this custom post type I will have N cities related.
I'm trying to create the files for theses pages and I thought this would work:
single.php - the generic one
single-cities.php - To list the cities
single-cities-{city-slug}.php - To bring the information for THE city
When I try:
/cities - It's showing the single.php content, not the single-cities content with the list.
/cities/sao-paulo - It's working. It shows the information about Sao Paulo.
Test:
If I delete the single-cities-{city-slug}.php, and try to access /cities/sao-paulo, it will bring the single-cities.php
What am I doing wrong in this hierarchy?
My code to register the custom post type:
$city_args = array(
'labels' => $labels,
'public' => true,
'has_archive' => true,
'publicly_queryable' => true,
'query_var' => true,
'capability_type' => 'post',
'hierarchical' => false,
'supports' => array(
'title'
),
'exclude_from_search' => false,
'menu_icon' => 'dashicons-building'
);
register_post_type('cities', $city_args);
Thanks!
UPDATE
I think I misunderstood the concept of a single page. The single.php is just to render a single post, not to list the posts for a custom post type.
Reading more about this hierarchy, I'm trying to understand how my structure of listing cities and then bring the city information would fit.
Maybe I should create a page for cities, and then inside this page (page-cities.php), create the code to bring all the cities.
Clicking on each city, it should go to the single.php, is that it??