We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 995
    • 8 Posts
    Some background info
    PHP 5, MySQL 5, Apache 2, Ubuntu server, MODx Revolution 2.0.4-pl2

    I’m following the instructions in Creating a Blog in MODx Revolution and have the required Extras installed.

    I’m having a problem where I try to display a list of latest blog posts. I am able to display the posts however, for each result, it will return the latest blog entry.

    I have a slightly different container set up:

    Home (1)
    A page (2)
    Blog (3) (container)
    - 2010 (4) (container) (hidden from menu)
    - A blog post (5)
    - Another blog post (6)
    - A blog post (7)

    I am using the following code in my page to call the snippet chunk recentBlogPost.

        [[!getResources? 
          &tpl=`recentBlogPost`
          &parents=`3`
          &hideContainers=`1`
          &limit=`5`
          &sortby=`publishedon` 
        ]]
    


    The snippet chunk recentBlogPost contains the following:
    <li><a title="[[+pagetitle]]" href="[[~[[+id]]]]">[[+pagetitle]]</a></li>
    


    I would appreciate someone pointing me in the right direction, what am I missing?
      • 28215
      • 4,149 Posts
      <li><a title="[[+pagetitle]]" href="[[~[[+id]]]]">[[+pagetitle]]</a></li>

      Should be in a *Chunk* called "recentBlogPost", not a Snippet.
        shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
        • 995
        • 8 Posts
        Sorry, I did mean chunk! Post updated.
          • 22303 MODX Staff
          • 10,725 Posts
          Quote from: alexisbm at Nov 20, 2010, 10:10 PM

          I’m having a problem where I try to display a list of latest blog posts. I am able to display the posts however, for each result, it will return the latest blog entry.
          Have you updated to the latest getResources? Are you saying it is returning the same post multiple times? I certainly can’t reproduce that.
            • 995
            • 8 Posts
            Yes, it will return the most recent post (in my case resource 7). I originally had just resource 5, I duplicated it to create resource 6. At that point I noticed the same resource being returned by getResources. I then created a new resource (7) as I thought it may have something to do with duplicating the resource. I’m not sure if that helps.

            I’m running the latest version of getresources (1.2.2).
              • 995
              • 8 Posts
              UPDATE: I have found the cause of this problem - the chunk recentBlogPost was being included as a separate file i.e. How to include a file as content. I really should have said so originally; hindsight is a wonderful thing. My chunk is really:
              [[includeFile?&phpfile=assets/chunks/recentBlogPost.php]]
              


              The includeFile snipper is:
              //check if there's a file given.
              if ( !isset($phpfile) || $phpfile == "" ) return "No file specified.";
              
              //Start the buffer
              ob_start();
              
              //include
              include $phpfile;
              
              //get contents from the buffer
              $ob_contents = ob_get_contents();
              
              //and kill/delete the buffer
              ob_end_clean();
              
              //return it to MODx
              return $ob_contents;
              


              This leads me to my next question, is it still possible to keep my chunk in a separate file? smiley
                • 22303 MODX Staff
                • 10,725 Posts
                No, that is not possible using that approach with getResources. You can use
                @FILE path/to/file.tpl
                instead of a Chunk name however, with getResources, in any of the *tpl properties.
                  • 995
                  • 8 Posts
                  Thanks for your help. Just to clarify, I have updated my getResources call to:

                  [[!getResources? 
                        &tpl=`@FILE assets/chunks/recentBlogPost.php`
                        &parents=`3`
                        &hideContainers=`1`
                        &limit=`5`
                        &sortby=`publishedon` 
                  ]]
                  


                  This outputs an array of each resource, wrapped in <pre> tags. What am I missing? I suppose I need to look into bindings...?