OK, that should make it somewhat easier. If all articles had an image, you could use getResources, but it sounds like that's not the case so you'd have to roll your own. I'm making some guesses here (e.g., that the TV contains a path to the image) -- something like this (untested):
Put this tag in where the image path goes:
[[!getArticleImage]]
Then create a snippet called getArticleImage:
<!--?php /* getArticleImage snippet */ $c = $modx--->newQuery('modResource'); $c->where(array( 'hidemenu' => '1', 'published' => '1' )); $c->sortby('publishedon','DESC'); $c->limit(10); $resources = $modx->getCollection('modResource', $c); foreach($resources as $resource) { $imagePath = $resource->getTVValue('name of image TV here'); if (!empty($imagePath)) { return $imagePath; } } return 'path_to_some_default_image';
This code (if it works) will check the 10 most recent articles for an image and return the first one found. It will also pull non-article resources that are published and hidden from menus, but there shouldn't be very many of them and they won't have the image TV filled so it will skip them. You can change the limit() number to search more or fewer articles.
------------------------------------------------------------------------------------------
PLEASE, PLEASE specify the version of MODX you are using.
MODX info for everyone: http://bobsguides.com/modx.html
This question has been answered by multiple community members. See the first response.
Hello! I tried Bob's snippet and it works fine. How can I use phpThumbOf on the snippet to resize the TVvalue instead of outputting a full sized image?
Thanks in Advance.
<a href="[[~[[+id]]]]"> [[!getArticleImage:phpThumbsUp=`w=200&h=150&zc=1&q=80`]] </a>
Warning: file_get_contents(myserver/<img src="/client-assets/gallery/4/22.jpg" style="padding: 10px 10px 10px 10px" alt="" />) [function.file-get-contents]:
<a href="[[~[[+id]]]]"> [[!getArticleImage:phpthumbof=`w=120&h=120`]] </a>