We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 22303 MODX Staff
    • 10,725 Posts
    Here’s an old NewsParser snippet variation I created back at Etomite that does work with multiple instances per page.

    Extract this into the directory /assets/snippets/newsparserx/ and then copy and paste the newslisting.snippet.txt contents into a new snippet that you can call from your pages.

    Sample Call
    $snippetOutput .= $modx->runSnippet('NewsParserX',array('url'=>'http://domain.tld/feed_url'));
    


    [UPDATE: version 0.9 posted 2006-04-02 to address html entities in complex feed URLs, e.g. those will query string parameters]
      • 6726
      • 7,075 Posts
      Waow Jason, just when we were discussing this !

      That was fast !!!
      Thanks smiley
        .: COO - Commerce Guys - Community Driven Innovation :.


        MODx est l'outil id
        • 28042 ☆ A M B ☆
        • 24,524 Posts
        I’ve never worked with newsfeeds before. How would I get the rss feed from here?

        http://modxcms.com/forums/index.php?sa=recent;type=rss2;action=.xml&limit=20


        Is this the url I use? Do I need to make another snippet to call the NewsParserX snippet, or can I call the NewsParserX snippet directly in my template?

          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
          To answer my own questions: Yes, and yes.

          I created a second snippet named ParseNews, with just this code:

          return $modx->runSnippet('NewsParserX',array('url'=>'http://modxcms.com/forums/index.php?sa=recent;type=rss2;action=.xml&limit=6'));
          


          Called ParseNews in my template.

          And the results:
          http://www.sottwell.com
            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
            I have a question. The links open in the same browser window, taking the user out of my site. How would I go about having the links open in a new window?

            I hacked the newsparserx.inc.php file adding

            target="_blank"


            to all the links. Is there a better way?
              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
              • 6726
              • 7,075 Posts
              Thanks Susan for sharing all this, pretty useful !

              And, by the way, nice port of YAML theme : nice clean looking template smiley
                .: COO - Commerce Guys - Community Driven Innovation :.


                MODx est l'outil id
                • 28042 ☆ A M B ☆
                • 24,524 Posts
                The template is clean enough, but the CSS is a major ... something. The main css file calls three or four others, plus he provides css files for a couple of different layouts using the same template. I’ve been very careful to leave the basic html alone, and to leave the css completely alone. I just add what I need for the various forms and stuff I’ve added.
                  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
                  • 22303 MODX Staff
                  • 10,725 Posts
                  The best way to modify for opening links in a new browser window, if you are interested in keeping it XHTML/CSS compliant, is to use the rel attribute to describe links to be opened in a new window in a standard way. A common approach is using rel="external" to describe links like this, and then use a script like this to do the work:
                  function externalLinks() {
                   if (!document.getElementsByTagName) return;
                   var anchors = document.getElementsByTagName("a");
                   for (var i=0; i<anchors.length; i++) {
                     var anchor = anchors[i];
                     if (anchor.getAttribute("href") &&
                         anchor.getAttribute("rel") == "external")
                       anchor.target = "_blank";
                   }
                  }
                  window.onload = externalLinks;


                  Make sure the script is loaded in the HEAD of your document (either from an external file registered as a startup script or putting the script in the HEAD of your template), and in browsers that support JS and the DOM methods above, you’ll get appropriate navigation, and will be ready to support browsers that might not be able to follow the old target="_blank" links (think mobile devices and other specialized browser platforms) with full compliancy.
                    • 25663 MODX Staff
                    • 12,272 Posts
                    Jason, I think you need to make a plugin out of that... would be killer!
                      Ryan Thrash, MODX Co-Founder
                      Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
                      • 28042 ☆ A M B ☆
                      • 24,524 Posts
                      If it can’t connect to the given URL it puts up a nasty MODx error page. I haven’t been able to get it to simply return false on failure to connect.
                        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