We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 39632
    • 13 Posts
    Quote from: BobRay at May 18, 2012, 01:51 AM
    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


    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.

    This question has been answered by multiple community members. See the first response.

    [ed. note: nunofil last edited this post 10 years, 10 months ago.]
      MODX Revolution 2.2.8-pl
    • discuss.answer
      • 41970
      • 79 Posts
      Quote from: nunofil at Jul 06, 2013, 07:13 PM


      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.


      I am quite new with modX, so I might be completely wrong and think too simple, but did you try [[!getArticleImage:phpthumbof=`w=600&h=450&zc=1&q=100`]] ?
      • discuss.answer
        • 3749
        • 24,544 Posts
        That looks pretty good to me, though you might try PhpThumbsUp instead. By most reports, it's faster and less troublesome. [ed. note: BobRay last edited this post 10 years, 10 months ago.]
          Did I help you? Buy me a beer
          Get my Book: MODX:The Official Guide
          MODX info for everyone: http://bobsguides.com/modx.html
          My MODX Extras
          Bob's Guides is now hosted at A2 MODX Hosting
          • 39632
          • 13 Posts
          Thank you bblinda and Bob.

          I tried:

          <a href="[[~[[+id]]]]">
          [[!getArticleImage:phpThumbsUp=`w=200&h=150&zc=1&q=80`]]
          </a>
          


          ... but I get the same result, as before, no image resize, just the full sized one, I also cleared the cache.
          Don't know I what I'm doing wrong? [ed. note: nunofil last edited this post 10 years, 10 months ago.]
            MODX Revolution 2.2.8-pl
            • 3749
            • 24,544 Posts
            Check the spelling of phpThumbsUp against the name of the snippet. I think it's phpthumbsup.
              Did I help you? Buy me a beer
              Get my Book: MODX:The Official Guide
              MODX info for everyone: http://bobsguides.com/modx.html
              My MODX Extras
              Bob's Guides is now hosted at A2 MODX Hosting
              • 39632
              • 13 Posts
              I've tried pThumb (I couldn´t find thumb Plus, probably is this pThumb) but I get this output(error) on the frontend of the site:

              Warning: file_get_contents(myserver/<img src="/client-assets/gallery/4/22.jpg" style="padding: 10px 10px 10px 10px" alt="" />) [function.file-get-contents]: 



              Using this:
              <a href="[[~[[+id]]]]">
              [[!getArticleImage:phpthumbof=`w=120&h=120`]]
              </a>
              


              Its working now. I changed the base url . Thank you both, for pointing me in the right direction. [ed. note: nunofil last edited this post 10 years, 10 months ago.]
                MODX Revolution 2.2.8-pl