Jump to content

Making my title a link


nicky666

Recommended Posts

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

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;
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.