skip to content
AdaWiki
User Tools
Log In
Site Tools
Search
Tools
Show page
Old revisions
Backlinks
Recent Changes
Media Manager
Sitemap
Log In
>
Recent Changes
Media Manager
Sitemap
You are here:
start
»
tutorials
»
zencartmods
»
blog_ticker.html
Trace:
tutorials:zencartmods:blog_ticker.html
==== Create a Blog Ticker on your homepage ==== If you have a blog that generates an rss feed, you can use the rss feed to pull in recent blog posts and post them to your home page. For this example we'll be using our rss that is generated automatically from Wordpress ([[http://www.adafruit.com/blog/feed|http://www.adafruit.com/blog/feed]]). ==== PHP DOM ==== Add this to your template, wherever you'd like to see the ticker. We chose **includes/templates/YOUR_TEMPLATE/templates/tpl_index_default.php** around line 12 (we have a large image above it). <code php> <div id="ticker" > <?php // Begin blog ticker mod $url = 'http://www.adafruit.com/blog/feed/'; // Change this to your own rss feed $num_posts = 5; // change this to the number of posts that you would like to show $doc = new DOMDocument(); $doc->load($url); $arrFeeds = array(); foreach ($doc->getElementsByTagName('item') as $node) { $itemRSS = array ( 'title' => substr($node->getElementsByTagName('title')->item(0)->nodeValue, 0, 100), // truncate the title to 100 character to fit in our layout 'link' => $node->getElementsByTagName('link')->item(0)->nodeValue ); $arrFeeds[] = $itemRSS; if (count($arrFeeds) >= $num_posts) continue; } for ( $i = 0; $i < $num_posts; $i++) {?> <div class="tickerText" id="tickerText<?php echo $i; ?>"> Latest Blog Posts: <a href="<?php echo $arrFeeds[$i]['link']; ?>"><?php echo $arrFeeds[$i]['title']; ?></a> </div> <?php } ?> <script language="javascript"> tickerFade(); </script> </div> </code> The first **foreach** loop parses out all of the posts from the XML file, the next **for** loop prints them to the page. Upload it and make sure that you're getting all the posts you want displayed in a row. ==== Javascript/CSS ====
/home/ladyada/public_html/wiki/data/attic/tutorials/zencartmods/blog_ticker.html.1312213264.txt.gz
· Last modified: 2016/01/28 18:05 (external edit)
Page Tools
Show page
Old revisions
Backlinks
Back to top