1

I'm currently trying to get my URL's to be like the following:

category/brand/offer/
  • Category has a title
  • Brand has a 'shortName' property.
  • Offer has a title

My plan is to have it so that it goes something like fashion/asos/50-off

{parent.uri}/offers/{slug}

I've tried quite a few variations but can't seem to get it right, still loads a 404 page or throws an error in the dashboard when trying to save entries again.

Any help would be brilliant!

EDIT

  • Offer entries are related via the relatedBrand entry field.
  • Offer has not category related to it.
  • Brands have a category field.
  • 1
    Do you already have relationships set up between your offer entries and their category & brand? What type of fields are you using, and what are their handles? Are they required? – Brandon Kelly Jan 20 '18 at 23:14
  • Hi Brandon, Yes, offers have a relatedBrand entries field. e.g. 50% off asos has a field where you attach a relatedBrand e.g. asos. Brand entries have a category field but offers don't. edited the question to include more info. – JMKelley Jan 21 '18 at 13:00
5

There are two ways you can set that up, depending on whether you want Brand entries to have a similar URI format (just without the 3rd segment), e.g. category/brand.

Assuming you do, edit your Brands section, and give it the following Entry URI Format:

  • Craft 2:

    {category.first().slug}/{slug}
    
  • Craft 3:

    {category.one().slug}/{slug}
    

Then edit your Offers section, and give it the following Entry URI Format:

  • Craft 2:

    {relatedBrand.first().uri}/{slug}
    
  • Craft 3:

    {relatedBrand.one().uri}/{slug}
    

Basically you’re telling Craft when defining an offer entry’s URI, to start with its related brand’s URI, and then tack on the offer’s slug as an additional segment.

If my assumption is wrong, and you don’t want to give brands a similar URI format, then just build the whole thing out from your Offers section:

  • Craft 2:

    {relatedBrand.first().category.first().uri}/{relatedBrand.first().slug}/{slug}
    
  • Craft 3:

    {relatedBrand.one().category.one().uri}/{relatedBrand.one().slug}/{slug}
    

(I’m also assuming that the brands’ category field’s handle is category. If not, replace category with the real handle.)

Brand has a 'shortName' property.

If that is a custom field that you would like to use instead of the brand entries’ slugs, just replace slug with shortName where appropriate.

| improve this answer | |
  • Amazing Brandon - thank you so much for this! – JMKelley Jan 21 '18 at 23:49
  • Hi Brandon, is it possible to use the relatedBrands category uri with the offer url? – JMKelley Jan 22 '18 at 23:47
  • @JMKelley as in, don’t include the brand segment - just category/offer? – Brandon Kelly Jan 23 '18 at 3:16
  • Hi Brandon, I mean just so it keeps the URL structure for google e.g. Brands = /category/brand, then offers = /category/relatedbrand/offer I've tried a few but it seems to hang and fail :( – JMKelley Jan 23 '18 at 9:30

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.