问题
I have created a news RSS feed for my website but want to display is in a format similar to http://www.apple.com/hotnews/ How would I put code onto my HTML page which would take the items from my RSS?
回答1:
You could use XSLT and CSS.
If you didn't care about links working, etc., then just use CSS.
For instance, here is how I style one of the RSS feeds on one of my sites:
channel link, channel language, channel copyright, channel managingEditor, channel webMaster, channel docs, channel lastBuildDate, channel item pubDate {display:none;}
rss {font-family:Arial, Helvetica, sans-serif;}
channel title {display:block; padding:1em; color:#FFF; border-bottom:1px solid black; font-weight:bold;font-size:140%; background-color:#4483C7;}
channel description {display:block; float:left; font-size:130%; margin:1em;}
channel item {border:1px solid #4483c7;clear:both; display:block; padding:0.5em; margin:1em;}
channel item title {background-color:#4483c7; border-bottom-width:0; color:#FFF; display:block; font-size:110%; font-weight:bold; margin:0; padding:0.2em;}
channel item description {display: block; float:none; margin:0; text-align: left; padding:0.2em 0.5em 0.4em; color: black; font-size:100%; font-weight:normal;}
channel item link {color:#666; display:block; font-size:86%; padding:0 0.5em;}
The result is this: http://www.ourladyofgrace.com/Bulletins/olg_bulletins.xml
If you want to make the page "work", then use XSLT.
Here's some info. http://www.paulwest.co.uk/article.php/styling-rss-news-feeds-with-xslt
回答2:
Since HTML is layout-only, then it has nothing to do with displaying RSS feed. Unless you want the same layout as apple does (I think you don't.)
You need PHP, javascript or maybe even flash for that.
- PHP solution
- JavaScript solution
- Flash solution
Pick your poison!
来源:https://stackoverflow.com/questions/5444481/rss-feed-display