nicky666 Posted January 31, 2014 Share Posted January 31, 2014 Hi I'm trying to create a rss feed and I would like to make the title the link that goes to its respective news. When I add the <a> tags everything disappears but it shows up in the page source and if I remove the <a> tags the it shows up in the web page but the title doesn't link to anything. <?php ini_set('display_errors', 1); header("Content-type: text/xml"); include("config.php"); global $NEWS; $str = '<?xml version="1.0" encoding="UTF-8"?>'; $str.= '<rss version="2.0">'; $str.='<channel>'; $sql = "SELECT * FROM $NEWS"; $result = mysql_query($sql) or die ($sql."".mysql_error()); while($row = mysql_fetch_object($result)){ $str.= '<item>'; $str.=' <a href="'.getSEOLink(13).'&article='.$row->id.'">'; $str.= '<title>'.$row->title.'</title></a>'; $str.= '<description><![CDATA['.$row->content. ']]></description>'; $str.= '</item>'; } $str .='</channel>'; $str .='</rss>'; echo $str; ?> Quote Link to comment Share on other sites More sharing options...
paddy_fields Posted January 31, 2014 Share Posted January 31, 2014 (edited) You need to close the <a> tag as well. The content between the tags is what will be displayed as the text on the link. <a href="the_address.php">the link text</a> EDIT: sorry, scrap that, I just saw it's on the next line Edited January 31, 2014 by paddyfields Quote Link to comment Share on other sites More sharing options...
cyberRobot Posted January 31, 2014 Share Posted January 31, 2014 Here are a list of tags to use within the <item> tag for an RSS feed: http://validator.w3.org/feed/docs/rss2.html#hrelementsOfLtitemgt Quote Link to comment Share on other sites More sharing options...
Solution nicky666 Posted January 31, 2014 Author Solution Share Posted January 31, 2014 I finally got it to work. I had to remove the <a> tags and put <link> elements in and the I had to remove the & and put in & Here is my code so that someone else can understand what I mean. <?php ini_set('display_errors', 1); header("Content-type: text/xml"); include("config.php"); global $NEWS; $str = '<?xml version="1.0" encoding="UTF-8"?>'; $str.= '<rss version="2.0">'; $str.='<channel>'; $sql = "SELECT * FROM $NEWS"; $result = mysql_query($sql) or die ($sql."".mysql_error()); while($row = mysql_fetch_object($result)){ $str.= '<item>'; $str.= '<title>'.$row->title.'</title>'; $str.= '<link>'.getSEOLink(13).'&article='.$row->id.'</link>'; $str.= '<description><![CDATA['.$row->content. ']]></description>'; $str.= '</item>'; } $str .='</channel>'; $str .='</rss>'; echo $str; ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.