Search code examples
modxmodx-revolution

MODx Revo. How to show the first image of a blog post on the main page?


I use MODx Revolution. On the home page we show some of the excerpt of the content (introtext).

<h2 class="title"><a href="[[~[[+id]]]]">[[+pagetitle]]</a></h2>
<p>[[+introtext]]</p>
<p class="postmeta">
<a href="[[~[[+id]]]]" class="readmore">read more</a> 
| <span class="date">[[+publishedon:strtotime:date=`%m/%d/%y`]]</span>
</p>

This is the guide I've used.

how display on the main page as the first image of the article?


Solution

  • You need to make a Template Variable eg 'BlogImage' of type 'Image' and assign that TV to your blog post template. Then upload your image to that field within each blog post and you can then access it with:

    img src="[[+tv.BlogImage]]"

    That will output your image from the TV.

    To output this image on a different template EG your homepage template you need to do a GetResources or GetResourceField call, which requires the installation of packages through the Revo Package Manager.

    hope that helps.