Skip to content
Grav 2.1 is out: every page speaks Markdown. Read the announcement →

Show first image post in another page

Started by Pedro Oliveira 7 years ago · 1 replies · 1017 views
7 years ago

Hi,

I've setup a blog type page in the , all working great, and I'm trying to list some posts in another page.

I can list the post title with url, but can´t figure out how to show first image of each post.

TWIG
              {% for post in page.find('/publicacoes').children.order('date', 'desc').slice(0, 2) %}
              {% set image = page.media.images|first %}
                <li class="recent-posts">
                    <strong>
                      <a href="{{ post.url }}">
                        {% if image %}
                            {{ image.cropZoom(800,800).html }}
                        {% endif %}
                      {{ post.title }}
                    </a>
                    </strong>
                </li>
            {% endfor %}

The code Is calling images from the current page instead of /publicacoes/children.

Any help is appreciated.
Cheers,
Pedro

7 years ago

Found the culprit.

TWIG
          {% set image = page.media.images|first %}

Should be:

TWIG
          {% set image = post.media.images|first %}

Cheers!
Pedro

Suggested topics

Topic Participants Replies Views Activity
Support · by Marcel, 5 days ago
0 85 5 days ago
Support · by JakobDB, 6 days ago
1 91 6 days ago
Support · by ramenos, 7 days ago
3 103 6 days ago
Support · by gravinator, 2 weeks ago
3 229 7 days ago
Support · by Roger Parkinson, 2 weeks ago
3 308 2 weeks ago