0

I am trying to get the exact same hierarchy structure of this site: https://theculturetrip.com/

To me it seems they have this category hierarchy:

-Continent
——-Country
————–City
-Food and Drink
-See and Do
-Art
-Literature
-etc.

If you click on a continent you will land on a page with posts in that continent sorted by the categories above (food and drink, art, literature, see and do).

Then if you click on a country you land on a page with posts in that country sorted by the same categories above (food and drink, art, literature, see and do).

Then if you click on a city you will land on a page with posts in that city sorted again… by the same categories above (food and drink, art, literature, see and do).

If you instead of clicking on a city you click on a category such as food and drink, you will be taken to a page where all the food and drink posts for that city appear (BUT NOT ALL FOOD AND DRINK POSTS IN GENERAL).

So my question is, is the category hierarchy they used as I described above? Or is it like this:

-Continent
-Food and Drink for this Continent
-See and Do for this Continent
-Art for this Continent
-Literature for this Continent
-etc.
——-Country
——-Food and Drink for this Country
——-Art for this Country
——-Literature for this Country
——-etc. for this Country
————City
————Food and Drink for this Country
————See and Do for this Country
————Art for this Country
————Literature for this Country
————etc. for this Country

This would lead to hundreds if not thousands of categories due to all the cities and countries this would need to be created for. Or would this rather be done by creating different pages for every single one of these?

I want to set my site up in the same exact way as this, but i just dont know how best to build the relationships.

Can somebody help with a solution here?

Thanks!

2 Answers 2

0

More than categories, you have custom taxonomy, it's easy to add custom taxonomy to post edit screen and retrieve these custom taxomnomies according to any logic with a custom WP_Query.

An example:

function continent_init() {
// create a new taxonomy
register_taxonomy(
    'continent',
    'post',
    array(
        'label' => __( 'Continent' ),
        'rewrite' => array( 'slug' => 'continent' )
    )
);
}
add_action( 'init', 'continent_init' );

The query to retrieve it (a [pre_get_posts][3] will be better than this)

$args = array(
'tax_query' => array(
    array(
        'taxonomy' => 'continent',
        'field' => 'slug',
        'terms' => 'europe'
    )
)
);
$query = new WP_Query( $args );

Hope it helps

6
  • Thanks for this info. That definitely helps. I will give this a try now. Once I have created a taxonomy for the places, then how can I create an archive page that functions the same way as the "/category/" archive pages. Can I build a page using ordinary page builder on wordpress, and somehow make this the standard format for all /Continent, /Country, and /City pages?
    – Alex
    Commented Jan 6, 2017 at 21:25
  • To create taxonomy page you just need to copy and rename the default tax or archive page of your theme, and in this file you can call any template part ie content-city.php. read more about the template hierarchy could be great developer.wordpress.org/themes/basics/template-hierarchy
    – Benoti
    Commented Jan 6, 2017 at 22:09
  • So I also have the option to create a Page for every country and every city, which would result in hundreds of pages. And in those pages I could filter manually using tags the content for food, restaurants, etc. Would this be bad practice? By building a taxonomy for 1. continent 2. country 3. city I could create logic with the wp_query that would pull the posts sorted by the logic that i choose (categorized by food, restaurants, etc. for that location) is this correct?
    – Alex
    Commented Jan 6, 2017 at 22:48
  • I don't think you should create taxonomy page for each country, where pre_get_posts can handle all logic. You can have different pregetposts for each custom tax.
    – Benoti
    Commented Jan 6, 2017 at 23:04
  • Ok so Ive created a hierarchal taxonomy for Places (with continent > Country > City). Ive also created a custom archives Page (Places_Archive.php) So now I am confused about where I put the query exactly in my code.
    – Alex
    Commented Jan 7, 2017 at 0:54
0

@Benoti

Thanks for this info. That definitely helps. I will give this a try now.

Once I have created a taxonomy for the places, then how can I create an archive page that functions the same way as the "/category/" archive pages. Can I build a page using ordinary page builder on wordpress, and somehow make this the standard format for all /Continent, /Country, and /City pages?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.