1

I'm trying to loop through entries in specific sections and output Entry's: - URL - Title - Type - Asset's image - asset's URL - Section's name - Section's URL - Tag's name - Tag's URL

So far I came to this with having difficulties with section's URL and tags that belongs to relative entry.

        {% set entries = craft.entries.section(['worldTechnology','worldTravel']) %}
        {% for entry in entries %}
        <div class="uk-width-medium-1-3">
        <div class="uk-panel uk-panel-box uk-panel-box-primary">
                <div class="uk-panel-teaser">
                    <a href="{{ entry.url }}">
                    <img class="uk-margin-bottom" src="http://cdni.wired.co.uk/1920x1280/k_n/London_5.jpg" alt="">
                    <h3 class="uk-h3 uk-text-center uk-margin-top uk-panel-header">{{ entry.title}}</h3>
                    </a>
                </div>
                <div class="uk-text-center">
                    <em>in</em>
                    <span class="uk-margin-small-left"><a href="{{ section.getUrl }}">{{ entry.section.name }}</a></span>
                    <span class="uk-margin-small-left">{{ entry.getType.name }}</span>
                    <ul class="uk-breadcrumb">
                        {% for tag in craft.tags.relatedTo(entries) %}
                        <li>
                            <a href="" class="uk-badge uk-badge-tag uk-badge-clean">
                            <i class="uk-icon-circle-thin uk-margin-small-right"></i>
                            {{ tag.title }}
                            </a>
                        </li>
                        {% else %}
                        <li>
                            No tags found
                        </li>
                    {% endfor %}
                    </ul>
                </div>
        </div>
        </div>
        {% endfor %}

I'm working on it only in evenings and I'm starting to like Craft and Twig. Hopefully some of you guys, will advice me or give me some direction to go after.

Thanks for viewing it.

2

Sections do not have URLs, so section.getUrl will not return anything for you.

If you are trying to get an index page of all the entries in a section that has a URI, try slicing off the last segment of the entry's URL, and make sure you have an index.html template in that section's template folder. Take a look at the templating documentation for more information on this.

For the tags, make sure you call {% for tag in craft.tags.relatedTo(entry) %} instead of {% for tag in craft.tags.relatedTo(entries) %} to get the tags related to the entry you are currently focused on in the for loop.

Hope this helps!

  • Thank you Aberkie :) I saw somewhere that sections don't have URLs, but I think didn't catch it. Tags works as it should! – Dominik Krulak Feb 16 '15 at 17:20
  • To "slicing off the last segment of the entry's URL". Do you mean, to get rid off a {slug}, so only section's URL left? How do you propose to do that? I've searched documentation, but I didn't see anything like that. – Dominik Krulak Feb 16 '15 at 20:12

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.