1

I would like to add the URL of the channel entry I have selected (atm 2 channels are available to choose from), so I would like a url like:

summerhouses/product1

or

greehnouses/product2

how would I modify the code below to achieve this?

The code below just shows: /product1

{% for row in entry.homeFeaturedProducts.order('RAND()')|batch(4) %}
{% for entry in row %}
    <h2 class="product-card-title"><a href="{{ entry.getUrl }}">{{ entry.title }}</a></h2>
    <span class="product-card-desc">Product Description</span>
    <span class="product-card-price">{{ entry.price }}</span>
{% endfor %}        
{% endfor %}
1

Try this - using {{ entry.section }} and {{ entry.slug }}

{% for row in entry.homeFeaturedProducts.order('RAND()')|batch(4) %}
{% for entry in row %}
    <h2 class="product-card-title"><a href="{{ entry.section}}/{{ entry.slug }}">{{ entry.title }}</a></h2>
    <span class="product-card-desc">Product Description</span>
    <span class="product-card-price">{{ entry.price }}</span>
{% endfor %}        
{% endfor %}
  • Thanks, that does indeed work, but I now need to get the template to match with the url as the slug consists of 2 parts (which is what I wanted) and using an entry-type template which matches the section is throwing a 404: entry type handle is 'products' and the template name is also 'products' which works for urls with one slug but not for the additional as desired? – Kev N Feb 21 '18 at 20:37
  • I just changed the section url format setting to: {section}/{slug} and sorted – Kev N Feb 21 '18 at 20:48

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.