We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 4488
    • 10 Posts
    I found this PHP code online to display RSS feeds on a site (One static and one rotating{ie you can have multiple feeds that cycle}) and it works great in Modx (Thank you designers for making such a great package!). The only problem I have is that it won’t display images associated with the RSS feed.
    I unfortunately don’t know enough about RSS feeds or PHP to add the needed code to fix it. I have contacted the original author, but the last time they were on the board that I found the code on was back in 02/11 and I emailed them as well and have heard nothing back.
    I was hoping if I posted it here someone might be able to mod the code to fix the image display problem. I know I could always use Java to do this, but I really really really want to do it in PHP.

    Here is the {Rotating Code}
    <?php
    $insideitem = false;
    $tag = "";
    $title = "";
    $description = "";
    $link = "";
    $locations = array(’http://michaelthompson.org/news/goo-world.xml’, ’http://forums.seochat.com/external.php’, ’http://michaelthompson.org/news/goo-world.xml’);
    srand((float) microtime() * 10000000); // seed the random gen
    $random_key = array_rand($locations);
    function startElement($parser, $name, $attrs) {
    global $insideitem, $tag, $title, $description, $link;
    if ($insideitem) {
    $tag = $name;
    } elseif ($name == "ITEM") {
    $insideitem = true;
    }
    }
    function endElement($parser, $name) {
    global $insideitem, $tag, $title, $description, $link;
    if ($name == "ITEM") {
    printf("<dt><b><a href=’%s’ target=new>%s</a></b></dt>",
    trim($link),htmlspecialchars(trim($title)));
    printf("<dt>%s</dt>

    ",htmlspecialchars(trim($description)));
    $title = "";
    $description = "";
    $link = "";
    $insideitem = false;
    }
    }
    function characterData($parser, $data) {
    global $insideitem, $tag, $title, $description, $link;
    if ($insideitem) {
    switch ($tag) {
    case "TITLE":
    $title .= $data;
    break;
    case "DESCRIPTION":
    $description .= $data;
    break;
    case "LINK":
    $link .= $data;
    break;
    }
    }
    }
    $xml_parser = xml_parser_create();
    xml_set_element_handler($xml_parser, "startElement", "endElement");
    xml_set_character_data_handler($xml_parser, "characterData");
    $fp = fopen($locations[$random_key], ’r’)
    or die("Error reading RSS data.");
    while ($data = fread($fp, 4096))
    xml_parse($xml_parser, $data, feof($fp))
    or die(sprintf("XML error: %s at line %d",
    xml_error_string(xml_get_error_code($xml_parser)),
    xml_get_current_line_number($xml_parser)));
    fclose($fp);
    xml_parser_free($xml_parser);
    ?>


    <End Rotating Code>


    Here is the <Static Code>
    <?php
    $insideitem = false;
    $tag = "";
    $title = "";
    $description = "";
    $link = "";
    function startElement($parser, $name, $attrs) {
    global $insideitem, $tag, $title, $description, $link;
    if ($insideitem) {
    $tag = $name;
    } elseif ($name == "ITEM") {
    $insideitem = true;
    }
    }
    function endElement($parser, $name) {
    global $insideitem, $tag, $title, $description, $link;
    if ($name == "ITEM") {
    printf("<dt><b><a href=’%s’>%s</a></b></dt>",
    trim($link),htmlspecialchars(trim($title)));
    printf("<dt>%s</dt>

    ",htmlspecialchars(trim($description)));
    $title = "";
    $description = "";
    $link = "";
    $insideitem = false;
    }
    }
    function characterData($parser, $data) {
    global $insideitem, $tag, $title, $description, $link;
    if ($insideitem) {
    switch ($tag) {
    case "TITLE":
    $title .= $data;
    break;
    case "DESCRIPTION":
    $description .= $data;
    break;
    case "LINK":
    $link .= $data;
    break;
    }
    }
    }
    $xml_parser = xml_parser_create();
    xml_set_element_handler($xml_parser, "startElement", "endElement");
    xml_set_character_data_handler($xml_parser, "characterData");
    $fp = fopen("http://michaelthompson.org/news/goo-world.xml","r")
    or die("Error reading RSS data.");
    while ($data = fread($fp, 4096))
    xml_parse($xml_parser, $data, feof($fp))
    or die(sprintf("XML error: %s at line %d",
    xml_error_string(xml_get_error_code($xml_parser)),
    xml_get_current_line_number($xml_parser)));
    fclose($fp);
    xml_parser_free($xml_parser);
    ?>

    <End Static Code>

    Thanks in advance.
      • 11055 ☆ A M B ☆
      • 3,112 Posts
      what is your modx version?
        Rico
        Genius is one percent inspiration and ninety-nine percent perspiration. Thomas A. Edison
        MODx is great, but knowing how to use it well makes it perfect!

        www.virtudraft.com

        Security, security, security! | Indonesian MODx Forum | MODx Revo's cheatsheets | MODx Evo's cheatsheets

        Author of Easy 2 Gallery 1.4.x, PHPTidy, spieFeed, FileDownload R, Upload To Users CMP, Inherit Template TV, LexRating, ExerPlan, Lingua, virtuNewsletter, Grid Class Key, SmartTag, prevNext

        Maintainter/contributor of Babel

        Because it's hard to follow all topics on the forum, PING ME ON TWITTER @_goldsky if you need my help.
        • 4488
        • 10 Posts
        Revolution 2.0.8
          • 11055 ☆ A M B ☆
          • 3,112 Posts
          do you use javascript for the rotating code?
            Rico
            Genius is one percent inspiration and ninety-nine percent perspiration. Thomas A. Edison
            MODx is great, but knowing how to use it well makes it perfect!

            www.virtudraft.com

            Security, security, security! | Indonesian MODx Forum | MODx Revo's cheatsheets | MODx Evo's cheatsheets

            Author of Easy 2 Gallery 1.4.x, PHPTidy, spieFeed, FileDownload R, Upload To Users CMP, Inherit Template TV, LexRating, ExerPlan, Lingua, virtuNewsletter, Grid Class Key, SmartTag, prevNext

            Maintainter/contributor of Babel

            Because it's hard to follow all topics on the forum, PING ME ON TWITTER @_goldsky if you need my help.
            • 4488
            • 10 Posts
            No, this is all done through the php code so you don’t have to use java (I don’t really want a java site, especially for something this simple). I did find out that if I tweak the style.css tags in the template, (IE use <div id="search"> instead of <div id="news"> {though for the life of me I can’t find the #search in the CSS file..so I have no idea where it’s coming from..}) I can eliminate the tags for the image so the feed is readable, but I would rather include the image from the feeds if I can.

            Here is the .css file if you want to take a look and tell me where/why the <div id="search"> works..:

            /*
            Design by Free CSS Templates
            http://www.freecsstemplates.org
            Released for free under a Creative Commons Attribution 2.5 License
            */

            body {
            margin: 0;
            padding: 0;
            background: #FFFFFF url(images/img01.jpg) repeat-x;
            font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
            font-size: 13px;
            color: #666666;
            }

            form {
            margin: 0;
            padding: 0;
            }

            fieldset {
            margin: 0;
            padding: 0;
            border: none;
            }

            input, textarea, select {
            font: normal 1em "Trebuchet MS", Arial, Helvetica, sans-serif;
            }

            h1, h2 {
            font-weight: normal;
            color: #7CD300;
            }

            h1 {
            letter-spacing: -1px;
            font-size: 2.6em;
            }

            h2 {
            font-size: 1.8em;
            }

            h3 {
            font-size: 1.2em;
            font-weight: bold;
            }

            p, ul, ol {
            }

            p {
            }

            blockquote {
            font-style: italic;
            }

            ul {
            }

            ol {
            }

            a {
            color: #7CD300;
            }

            a:hover {
            text-decoration: none;
            }

            small {
            }

            hr {
            display: none;
            }

            img {
            border: none;
            }

            img.left {
            float: left;
            margin: 0 15px 0 0;
            }

            img.right {
            float: left;
            margin: 0 0 0 15px;
            }

            /* Header */

            #header {
            width: 920px;
            height: 160px;
            margin: 0 auto;
            }

            /* Logo */

            #logo {
            float: left;
            }

            #logo h1, #logo h2 {
            margin: 0;
            text-transform: lowercase;
            }

            #logo h1 {
            padding-top: 52px;
            font-size: 4em;
            color: #554D49;
            }

            #logo h1 a {
            color: #554D49;
            }

            #logo h2 {
            margin-top: -10px;
            padding-left: 1px;
            letter-spacing: -1px;
            font-size: 1.8em;
            color: #7F7772;
            }

            #logo h2 a {
            color: #7F7772;
            }

            #logo a {
            text-decoration: none;
            }

            /* Menu */

            #menu {
            float: right;
            }

            #menu ul {
            margin: 0;
            padding: 40px 0 0 0;
            list-style: none;
            }

            #menu li {
            display: inline;
            }

            #menu a {
            display: block;
            float: left;
            width: 130px;
            height: 90px;
            padding-top: 30px;
            background: #73D000 url(images/img02.jpg) no-repeat;
            text-align: center;
            text-decoration: none;
            text-transform: lowercase;
            font-size: 1.6em;
            color: #FFFFFF;
            }

            /* Page */

            #page {
            width: 920px;
            margin: 0 auto;
            padding-top: 20px;
            }

            #latest-post {
            float: left;
            width: 480px;
            }

            #recent-posts {
            float: right;
            width: 380px;
            padding: 12px 0 0 30px;
            background: url(images/img03.gif) repeat-y;
            }

            #recent-posts .entry {
            background: url(images/img04.gif) repeat-x left bottom;
            }

            .post {
            }

            .post .title {
            margin: 0;
            }

            .post .meta {
            margin: 0;
            padding-bottom: 10px;
            line-height: normal;
            font-family: Arial, Helvetica, sans-serif;
            color: #BABABA;
            }

            .post .meta a {
            color: #BABABA;
            }

            .post .entry {
            margin-bottom: 10px;
            padding-bottom: 5px;
            }

            /* Sidebar */

            #sidebar {
            clear: both;
            width: 920px;
            background: #CDEB8B url(images/img05.gif) no-repeat;
            border-top: 20px solid #FFFFFF;
            color: #008C00;
            }

            #sidebar ul {
            margin: 0;
            padding: 0;
            list-style: none;
            }

            #sidebar li {
            display: block;
            float: left;
            width: 200px;
            padding: 15px;
            }

            #sidebar li ul {
            line-height: 1.8em;
            }

            #sidebar li li {
            display: list-item;
            float: none;
            width: auto;
            padding: 0;
            }

            #sidebar h2 {
            margin: 0 0 15px 0;
            color: #008C00;
            }

            #sidebar a {
            text-decoration: none;
            color: #008C00;
            }

            #sidebar a:hover {
            text-decoration: underline;
            }

            /* Footer */

            #footer {
            width: 920px;
            height: 100px;
            margin: 0 auto;
            background: url(images/img06.gif) no-repeat;
            }

            #footer p {
            margin: 0;
            padding: 15px;
            }

            #legal {
            float: left;
            }

            #links {
            float: right;
            }

              • 11055 ☆ A M B ☆
              • 3,112 Posts
              what is your snippet call for this snippet?
                Rico
                Genius is one percent inspiration and ninety-nine percent perspiration. Thomas A. Edison
                MODx is great, but knowing how to use it well makes it perfect!

                www.virtudraft.com

                Security, security, security! | Indonesian MODx Forum | MODx Revo's cheatsheets | MODx Evo's cheatsheets

                Author of Easy 2 Gallery 1.4.x, PHPTidy, spieFeed, FileDownload R, Upload To Users CMP, Inherit Template TV, LexRating, ExerPlan, Lingua, virtuNewsletter, Grid Class Key, SmartTag, prevNext

                Maintainter/contributor of Babel

                Because it's hard to follow all topics on the forum, PING ME ON TWITTER @_goldsky if you need my help.
                • 4488
                • 10 Posts
                The call is [[newsfds]]
                  • 11055 ☆ A M B ☆
                  • 3,112 Posts
                  why don’t you try one or two of already available rss feeders from extra?
                  http://modx.com/extras/category/feeds
                    Rico
                    Genius is one percent inspiration and ninety-nine percent perspiration. Thomas A. Edison
                    MODx is great, but knowing how to use it well makes it perfect!

                    www.virtudraft.com

                    Security, security, security! | Indonesian MODx Forum | MODx Revo's cheatsheets | MODx Evo's cheatsheets

                    Author of Easy 2 Gallery 1.4.x, PHPTidy, spieFeed, FileDownload R, Upload To Users CMP, Inherit Template TV, LexRating, ExerPlan, Lingua, virtuNewsletter, Grid Class Key, SmartTag, prevNext

                    Maintainter/contributor of Babel

                    Because it's hard to follow all topics on the forum, PING ME ON TWITTER @_goldsky if you need my help.
                    • 4488
                    • 10 Posts
                    The main reason I wasn’t using spieFeed or getFeed was because I couldn’t find a way to make it rotate through different feeds. If there is a way to load the feeds into an array and randomly select one to display then that would be the way to go... I just haven’t found how to make either one do that or if it’s even possible for them to do it.
                      • 11055 ☆ A M B ☆
                      • 3,112 Posts
                      If I’m not wrong, getFeed allows you to store the result in a placeholder.
                      You can create another snippet just to manage the placeholder.

                      Or,
                      Just create your own snippet based on getFeed / spieFeed, and change the return behavior.
                      Bear in mind, those snippets don’t set the output inline inside the PHP codes.
                      They use chunks.
                        Rico
                        Genius is one percent inspiration and ninety-nine percent perspiration. Thomas A. Edison
                        MODx is great, but knowing how to use it well makes it perfect!

                        www.virtudraft.com

                        Security, security, security! | Indonesian MODx Forum | MODx Revo's cheatsheets | MODx Evo's cheatsheets

                        Author of Easy 2 Gallery 1.4.x, PHPTidy, spieFeed, FileDownload R, Upload To Users CMP, Inherit Template TV, LexRating, ExerPlan, Lingua, virtuNewsletter, Grid Class Key, SmartTag, prevNext

                        Maintainter/contributor of Babel

                        Because it's hard to follow all topics on the forum, PING ME ON TWITTER @_goldsky if you need my help.