Importing multiple RSS feeds – using newsWidget (jQuery)

Tutorials

Some times ago I told how to display rss feed at our website. But some times ago my friend ask me how to display in single box feeds from multiple sources. I decided to investigate it and located NewsWidget library. Lets check its possibilities.

Here is a sample:

Live Demo 1
Live Demo 2
Live Demo 3

[sociallocker]

download in package

[/sociallocker]


Ok, download the example files and lets start coding !


Step 1. HTML

As usual, we will start with the HTML.

Here are sources of all 3 samples:

templates/sample1.html

01 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
02 <html>
03 <head>
04     <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
05     <title>Example 1 - NewsWidget jQuery Plugin</title>
06     <link rel="stylesheet" href="css/styles1.css" type="text/css" media="screen" />
07 </head>
08 <body>
09     <div id="newsWidget">
10         <div class="intro">Below you find some <strong>random</strong> rss feeds from few sources using extended format. Every <strong>15 seconds</strong> the list is updated.</div>
11         <ul id="news"></ul>
12     </div>
13     <script type="text/javascript" src="js/jquery.min.js"></script>
14     <script type="text/javascript" src="js/jquery.newsWidget.js"></script>
15     <script type="text/javascript">
17             proxyUrl: "get_rss_feed.php",
18             limitItems: 10,
19             refresh: 15000,
20             random: true,
21             itemDateElement: "span",
22             itemLinkElement: "span",
23             itemWebsiteTitleElement: 'span',
24             linkTitle: true,
25             format: "title,description,date,link,websiteTitle"});
26     </script>
27 </body>
28 </html>

templates/sample2.html

01 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
02 <html>
03 <head>
04     <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
05     <title>Example 2 - NewsWidget jQuery Plugin</title>
06     <link rel="stylesheet" href="css/styles2.css" type="text/css" media="screen" />
07 </head>
08 <body>
09     <div id="newsWidget">
10         <div class="intro">Below you find some the <strong>latest</strong> rss feeds from few sources using extended format.</div>
11         <ul id="news"></ul>
12     </div>
13     <script type="text/javascript" src="js/jquery.min.js"></script>
14     <script type="text/javascript" src="js/jquery.newsWidget.js"></script>
15     <script type="text/javascript">
17             proxyUrl: "get_rss_feed.php",
18             limitItems: 10,
19             random: false,
20             itemDateElement: "span",
21             itemLinkElement: "span",
22             itemWebsiteTitleElement: 'span',
23             linkTitle: true,
24             format: "title,date,websiteTitle, description"});
25     </script>
26 </body>
27 </html>

templates/sample3.html

01 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
02 <html>
03 <head>
04     <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
05     <title>Example 3 - NewsWidget jQuery Plugin</title>
06     <link rel="stylesheet" href="css/styles3.css" type="text/css" media="screen" />
07 </head>
08 <body>
09     <div id="newsWidget">
10         <div class="intro">Below you find some the <strong>latest</strong> rss feeds from few sources using easy format.</div>
11         <ul id="news"></ul>
12     </div>
13     <script type="text/javascript" src="js/jquery.min.js"></script>
14     <script type="text/javascript" src="js/jquery.newsWidget.js"></script>
15     <script type="text/javascript">
17             proxyUrl: "get_rss_feed.php",
18             limitItems: 10,
19             random: false,
20             itemDateElement: "span",
21             itemLinkElement: "span",
22             itemWebsiteTitleElement: 'span',
23             linkTitle: true,
24             format: "title,date"});
25     </script>
26 </body>
27 </html>

As you can see – these samples quite same, just list of params is different. Most of params described in JS library itself, but I used next: limitItems – how many elements we will display; refresh – refresh time (in ms, optional param); random – are elements will display randomly or not, format – array of elements which we going to display.

Step 2. CSS

Here are used CSS styles.

css/styles1.css

01 @charset "utf-8";
02 body{color:#333;font-family:Verdana,Arial,Helvetica,sans-serif;font-size:12px;text-align:center}
03 #newsWidget{text-align:left;margin:20px auto;width:250px;border:1px solid #cdcdcd;padding:10px}
04 #newsWidget .intro{background-color:#f5f5f5;padding:10px}
05 #newsWidget ul{margin-left:0;padding-left:0;list-style:none}
06 #newsWidget ul li{padding-left:20px;background-image:url(news.jpg);background-repeat:no-repeat;background-position:0 12px}
07 #newsWidget h4{font-size:12px;color:#424242;margin:0;padding:10px 0 5px}
08 #newsWidget .description{margin:0;padding:0 0 5px}
09 #newsWidget .date{font-size:10px;color:gray}
10 #newsWidget .date,#newsWidget .link{font-size:10px;color:gray;padding:0 5px 0 0;margin:0 5px 0 0;border-right:solid 1px gray}
11 #newsWidget .websiteTitle{font-size:10px;color:gray}
12 #newsWidget a:link,#newsWidget a:active,#newsWidget a:visited{color:#036}
13 #newsWidget a:hover{color:#f60}

css/styles2.css

01 @charset "utf-8";
02 body{color:#333;font-family:Arial,Helvetica,sans-serif;font-size:12px;text-align:center}
03 #newsWidget{text-align:left;margin:20px auto;width:250px;border:1px solid #cdcdcd;padding:10px;color:#333}
04 #newsWidget .intro{background-color:#f5f5f5;padding:10px}
05 #newsWidget ul{margin:0;padding:0;list-style:none}
06 #newsWidget ul li{border:3px solid #f2f2f2;display:block;margin:10px 0 0;padding:10px 24px 16px 28px;position:relative}
07 #newsWidget h4{font-size:17px;color:#424242;margin:0;padding:10px 0 5px;line-height:22px}
08 #newsWidget .description{color:gray;font-size:11px;line-height:15px;clear:both}
09 #newsWidget .date,#newsWidget .websiteTitle{font-size:10px;font-style:italic;line-height:13px;padding:0 4px 24px 0;display:block;float:left}
10 #newsWidget a:link,#newsWidget a:active,#newsWidget a:visited{border-bottom:1px solid #d8d8d8;color:#333;text-decoration:none}
11 #newsWidget a:hover{border-bottom-color:#333}
12 .spacer{clear:both;height:1px;display:block}

css/styles2.css

01 @charset "utf-8";
02 body{color:#bebebe;font-family:Arial,Helvetica,sans-serif;font-size:13px;font-weight:lighter;line-height:18px;text-align:center;background-image:url(background.jpg);background-repeat:repeat}
03 #newsWidget{text-align:left;margin:20px auto;width:250px;border:1px dotted #414141;padding:10px;color:#333}
04 #newsWidget .intro{background-color:#67afcb;padding:10px;color:#fff;margin-bottom:10px}
05 #newsWidget ul{margin:0;padding:0;list-style:none}
06 #newsWidget ul li{border-bottom:1px dotted #313131;margin:0 0 8px;padding:0 0 8px;display:block;position:relative}
07 #newsWidget h4{font-size:14px;color:#424242;margin:0;padding:2px 0 0;line-height:18px;display:block}
08 #newsWidget .date{color:#999;font-size:11px;clear:both}
09 #newsWidget a:link,#newsWidget a:active,#newsWidget a:visited{color:#67afcb;text-decoration:none}
10 #newsWidget a:hover{color:#79c0dc}
11 .spacer{clear:both;height:1px;display:block}

Step 3. JS

Current samples contain jquery.min.js library and jquery.newsWidget.js. I don`t included source codes of these libraries in post. It always available in package

Step 4. PHP

Here are one small PHP file:

get_rss_feed.php

1 <?php
2 $sUrl $_GET['url'];
3 header( 'Content-Type: text/xml' );
4 readfile($sUrl);
5 ?>

Live Demo 1
Live Demo 2
Live Demo 3

Conclusion

Today I told you how to import several RSS feeds using new jQuery library. You can use this material to create own scripts into your startups. Good luck!

Rate article