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; ?> Link to comment https://forums.phpfreaks.com/topic/285824-making-my-title-a-link/ Share on other sites More sharing options...
paddy_fields Posted January 31, 2014 Share Posted January 31, 2014 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 Link to comment https://forums.phpfreaks.com/topic/285824-making-my-title-a-link/#findComment-1467203 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 Link to comment https://forums.phpfreaks.com/topic/285824-making-my-title-a-link/#findComment-1467205 Share on other sites More sharing options...
nicky666 Posted January 31, 2014 Author 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; ?> Link to comment https://forums.phpfreaks.com/topic/285824-making-my-title-a-link/#findComment-1467206 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.