1

I have a technologies magazine and recently find out about Craft CMS. It looks like I can make everything that I need to but I need advice.

So basically we are writing about smartphones, cars, computers, games and etc. All of these I can put as categories but different posts also have different sub-categories. We split our content into three sub-categories: news, tips, reviews. That means that all the categories (like smartphones, cars and etc.) have the same sub-categories (news, tips, reviews).

I'm looking for the best option for sorting all our content in Craft CMS. I was thinking to use entry types but we also want to have separate archives where people can find only smartphones news or smartphones tips. At the same time, we want to have the archive with all the tips.

The idea is to have a structure like this:

Home -> device type -> post type -> article

Url structure should be with all these components included and all of them should have the archive. I was thinking to use categories for device type and entries type for post type but it gets a bit messy. Does anyone have better ideas on how I can make this thing working for me? Thanks!

1

There is no definite answer to your question but I think you can get pretty much what you want using just two types of categories.

Section setup

  1. create 2 category groups:
    • device types (with the deviceTypes)
    • post types (with the postTypes)
  2. create an Articles section (with the article handle)
  3. configure you section with the following Entry URI format: {articlesDeviceType.slug}/{articlesPostType.slug}/{slug}
  4. on the entry type of the articles section (you just need one entry type), add the following required custom fields:
    • Device type (with the articlesDeviceType handle)
    • Post type (with the articlesPostType handle)

Your entries should now have the URL structure you wanted.

Archive page

Now if you want an archive of all smartphone related tips, you can get the entries with the following entry query in a template:

{% set tipsCategoryId = craft.categories().group('postTypes').slug('tips').ids() %}
{% set smartphoneCategoryId = craft.categories().group('deviceTypes').slug('smartphones').ids() %}

{% set entryQuery = craft.entries().section('articles').relatedTo([
    'and', 
    { field: 'articlesPostType', targetElement: tipsCategoryId },
    { field: 'articlesDeviceType', targetElement: smartphoneCategoryId },
])

This should return an EntryQuery matching all entries related to both smartphones device type and tips post type.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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