We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 16680
    • 73 Posts
    Hi all,

    http://net.tutsplus.com/videos/screencasts/how-to-build-a-super-duper-news-scroller/

    I am trying to integrate this with my Modx site, but I am having some issues. Mainly because I suck badly at PHP.

    What I have done so far.

    Created my own Ditto feed (http://ditto.modxcms.com/tutorials/custom-rss-feed.html)
    -That was easy enough

    Created a snippet with the following code to get SimplePie going
    <?php
    require 'simplepie.inc';
    $feed = new SimplePie('http://net.tutsplus.com/rss');
    $feed->handle_content_type();
    ?>


    That was also pretty straight forward.

    Now I need to somehow get the html+php code for showing the actual news items into my template. The code looks something like this taken straight from the tutorial:

    		<ul id="widget">
    			<?php foreach($feed->get_items(0, 15) as $item) : ?>
    			<li>
    				<?php echo $item->get_description(); ?>
    				<h4><a href="<?php echo $item->get_permalink(); ?>"><?php echo $item->get_title(); ?></a></h4>
    				<p>
    					<?php echo $item->get_date(); ?>
    				</p>
    			</li>
    			<?php endforeach; ?>
    		</ul>


    The problem is here, that no matter how I try to include it, as a chunk or a snippet or directly into my template, it screws up badly, resulting in a blank page.

    So, my question is now, how can I include this without having to re-write it too much? (Since re-writing is hard when you are a php newb)

    Oh I also tried requiring it as a php file. That didnt work as well.

    Thanks to all that are still reading smiley

    -larsb
      Signature on it&#39;s way
      • 10449
      • 956 Posts
      This piece of code has HTML + PHP mixed together. Try adding opening and closing PHP tags around it and save it as a snippet. (or rewrite every HTML bit inside PHP, i.e. echo, and use just one PHP open- and close tag)
      Actually, I think you can just put it beneath the require(SP) block...
        • 16680
        • 73 Posts
        Hi Ganesh,

        Thanks for a fast reply.

        Just wrapping it in php tags and running it as a snippet, kind of worked. I didn’t get any errors, but then again, not content shows up.

        I have tried re-writing it as a php block, but there must be some errors in my code, because I get a blank page when running it. TextMate however, tells me that there are no syntax errors.

        <?php
        echo "<ul id=\"widget\">";
        foreach($feed->get_items(0, 15) as $item) :
        echo "<li>";
        echo $item->get_description();
        echo "<h4><a href=\"$item->get_permalink();\">$item->get_title();</a></h4>";
        echo "<p>";
        echo $item->get_date();
        echo "</p>";
        echo "</li>";
        endforeach;
        echo "</ul>";
        ?>
          Signature on it&#39;s way
          • 10449
          • 956 Posts
          try this...

          <?php
          
          require 'simplepie.inc';
          $feed = new SimplePie('http://net.tutsplus.com/rss');
          $feed->handle_content_type();
          
          $o = '';
          $o .= '<ul id="widget">';
          
          foreach($feed->get_items(0, 15) as $item) {
          	$o .= '<li>';
          	$o .= $item->get_description();
          	$o .= '<h4>';
          	$o .= '<a href="';
          	$o .= $item->get_permalink();
          	$o .='">';
          	$o .=$item->get_title();
          	$o .='</a></h4>';
          	$o .= '<p>';
          	$o .= $item->get_date();
          	$o .= '</p></li>';
          }
          
          $o .='</ul>';
          
          return($o);
          
          ?>
          


          but first of all: make sure the path to simplepie.inc is correct
            • 16680
            • 73 Posts
            Ganesh you are a God, hence your name smiley

            Thanks alot, it works like a charm now..
              Signature on it&#39;s way