We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 22967
    • 26 Posts
    Hai everyone,

    After finishing my template and trying implementing it to MODx, I came up with one problem which I am unable to fix. I tried searching the documentation and I *think* read all posts in this forum, unfortunately no luck.

    Here is the thing. I’ve got one folder *News* which contains all posted news. Now I want a section on every page which has about five posts summarries.

    I tried already making a snippet with @Document *folderID*, but that gives me a lot of errors. I also noticed that only the folder *News* can have the [[NewsListing?&startID=6]] to show all News listings.

    Does somebody know how to create this and if so could you help me please.

    Many thanks in advance.

    Cheers Paul
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      I’m not sure that I understand what it is you want to do. Do you want to show five summaries of news articles from your News folder on each page?
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 22967
        • 26 Posts
        Hai Susan,

        Thank you for replying and yes exactly. I would like to show the five latest posts(summaries) on every page.

        Cheers Paul
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          Then NewsListing will do just that. It has a lot of options that you can set as parameters when you call it in your document or template.

          *  Snippet parameters [default] :
           *      &startID       - the folder containing the posts [the document called from]
           *      &summarize     - number of posts to list partially/fully [3]
           *      &total         - max number of posts to retrieve [100] 
           *                     
           *      &trunc         - truncate to summary posts? if set to false, shows entire post [true]
           *      &truncSplit    - use the special "splitter" format to truncate for summary posts [true]
           *      &truncAt       - the split-point splitter itself [<!-- splitter -->]
           *      &truncLen      - if you don't have a splitter or you turn that off explicitly, the number 
           *                       of characters of the blog to show for summary if not using splitter [450] 
           *                       However, if you have a summary of the post, it will use that instead. 
           *                       DEPRECATED ... see below...
           *      &truncText     - text for the summary "show more" link
           *                     
           *      &comments      - whether or not the posts have comments [false]  
           *      &commText      - comments link text ["Read Comments"]  
           *                     
           *      &tpl           - name of the chunk to use for the summary view template  
           *      &dateformat    - the format for the summary date (see http://php.net/strftime ) [%d-%b-%y %H:%M]
           *      &pubOnly       - only show Published posts [true]
           *      &menuOnly      - only show docs with "show in menu" checked [true] TO BE IMPLEMENTED
           *      &emptytext     - text to use when no news items are found
           *      &archivetext   - text to use for the Post Archives listing ["Older Items"]
          
            Studying MODX in the desert - http://sottwell.com
            Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
            Join the Slack Community - http://modx.org
            • 22967
            • 26 Posts
            Hai Susan,

            Thanks again for your reply!! I read that also from the snippet. But the problem is that if I set the parameters in my template. I get or *no entries found* or I get some errors.

            I get these errors when calling the parameters through a TV or implementing them directly into the template:

            Fatal error: Cannot redeclare closetags() (previously declared in E:\WWW\modx\manager\includes\document.parser.class.inc.php(667) : eval()’d code:143) in E:\WWW\modx\manager\includes\document.parser.class.inc.php(667) : eval()’d code on line 198

            I noticed that the parameters are working if a different page(like home) is being displayed. Although if I go to the news-page I’ll get these errors again.

            Again thanks for helping.

            Cheers Paul
              • 28042 ☆ A M B ☆
              • 24,524 Posts
              The problem is that you are calling the snippet twice; probably once on the "news" page and once in the template. So it’s declaring its closeTags function each time, and you can’t do that. I’m looking into that...I think there’s a way of declaring a function only if it’s not already declared. Stay tuned!
                Studying MODX in the desert - http://sottwell.com
                Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                Join the Slack Community - http://modx.org
                • 28042 ☆ A M B ☆
                • 24,524 Posts
                Ok, got it. In the NewsListing function, at line 136, about half-way down, there is the function declaration. Put this on the line before the function code starts, like so:

                if(!function_exists(closeTags)) {
                function closeTags($text) { 
                


                That means "If ( NOT function_exists (closeTags) ) { go ahead and declare it } for you non-coders out there. Also note the { at the end of that line. We are going to enclose the whole function inside of this "if" statement, so at the end of the function code we have to close the statetment, at line 191,like this:

                    return $text.$endTags; 
                }
                } // end if function exists block
                


                I’ve attached the entire patched file (why is it a "patch" if something is fixed, but a "hack" if it’s just changed a bit to suit your fancy?) here. Just copy/paste the text over the old one.
                  Studying MODX in the desert - http://sottwell.com
                  Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                  Join the Slack Community - http://modx.org
                  • 22967
                  • 26 Posts
                  WOW thanks Susan!!!

                  That works like a charme smiley I am very happy with that one. Thank you again. Now I am going to try and implement it with the proper tpl. to it.

                  I will let you know if it’s finished.

                  Cheers Paul
                    • 22967
                    • 26 Posts
                    Ok got the following problem right now.

                    On every page the summary of a post is displayed correctly. Now I want, if somebody clicks the news-page, to display the full story.

                    I already tried to set the &trunc to false, but that didn’t help me.

                    Here is the line I that I have added:

                    [[NewsListing? &startID=`6` &trunc=’false’ &total=`20`]]


                    Cheers Paul
                      • 1876
                      • 835 Posts
                      Hi,

                      If you used : &trunc=’false’, you shows entire post.

                      You have to use : &trunc=’true’
                      choose your trunc method split or at
                      and &truncText to specifie the text for the summary "show more" link

                      Aour