jamesjmann Posted February 12, 2011 Share Posted February 12, 2011 How do you give pages that are generated using the _Get method it's own meta tags? Not sure if I'm explaining this properly so allow me to elaborate: When a visitor clicks on an article on my site, they get redirected to a new page (index.php?action=article1) within the original page (index.php). Now, since it's more or less the same page, the meta tags are the same, but I was wondering if there is a way I could make it to where each article has it's own unique tags so when a visitor, for instance, clicks "share on facebook", the title and description of that article appears. Does anyone know what I'm talking about? If so, is there a way to do this? Quote Link to comment Share on other sites More sharing options...
trq Posted February 12, 2011 Share Posted February 12, 2011 Meta tags are just another form of data. Considering your already dynamically generating data for each page (presumably from a database), I don't see how meta tag data is any different. I'm really not sure where your stuck here? Just create the meta tags as you would any other content. Quote Link to comment Share on other sites More sharing options...
jamesjmann Posted February 12, 2011 Author Share Posted February 12, 2011 Meta tags are just another form of data. Considering your already dynamically generating data for each page (presumably from a database), I don't see how meta tag data is any different. I'm really not sure where your stuck here? Just create the meta tags as you would any other content. I'm not exactly sure what you mean, because since my pages are generated dynamically, I can't exactly go into the header of each one and specify the meta tags using a variable. I would have to use an if statment, I think, like, if $page is true, echo <meta> tags $title $description, etc. Is that right? Quote Link to comment Share on other sites More sharing options...
trq Posted February 12, 2011 Share Posted February 12, 2011 I'm not exactly sure what you mean, because since my pages are generated dynamically, I can't exactly go into the header of each one and specify the meta tags using a variable. Sorry, you've lost me. Again, meta tag data is just data, the same as the rest of your data. Quote Link to comment Share on other sites More sharing options...
jamesjmann Posted February 12, 2011 Author Share Posted February 12, 2011 I'm not exactly sure what you mean, because since my pages are generated dynamically, I can't exactly go into the header of each one and specify the meta tags using a variable. Sorry, you've lost me. Again, meta tag data is just data, the same as the rest of your data. Ok, have you ever used the facebook share button? Well, whenever you click it, it takes you to a page that shows a graphic, title, and description of whatever it is you clicked on to share. Now, since I'm using these share buttons for individual articles that are dynamically created, I want the title of the article and description (as in the body), to appear there, because whenever someone clicks on one of my articles, the meta title and description used for the main page shows, which would be "Welcome to my website". Here's the php code that generates my pages; perhaps, this will help you understand a little better: switch($_GET['action']) { case 'show': displayOneItem($_GET['id']); break; case 'all': displayNews(1); break; case 'addcomment': addComment($_GET['id']); break; default: displayNews(); Quote Link to comment Share on other sites More sharing options...
trq Posted February 12, 2011 Share Posted February 12, 2011 perhaps, this will help you understand a little better: I understand perfectly what your trying to do. Quote Link to comment Share on other sites More sharing options...
jamesjmann Posted February 12, 2011 Author Share Posted February 12, 2011 perhaps, this will help you understand a little better: I understand perfectly what your trying to do. Do you know how I can achieve this, then? Quote Link to comment Share on other sites More sharing options...
trq Posted February 12, 2011 Share Posted February 12, 2011 I thought I already had. Quote Link to comment Share on other sites More sharing options...
jamesjmann Posted February 12, 2011 Author Share Posted February 12, 2011 I thought I already had. I'm pretty sure you didn't. This is what I'm talking about: http://www.codingforums.com/showthread.php?t=129123 Quote Link to comment Share on other sites More sharing options...
trq Posted February 12, 2011 Share Posted February 12, 2011 All you need to do is make sure that, instead of loading an already existing and complete <head> tag full of data, you dynamically add your <meta> tags along with the rest of your data. Quote Link to comment Share on other sites More sharing options...
jamesjmann Posted February 12, 2011 Author Share Posted February 12, 2011 All you need to do is make sure that, instead of loading an already existing and complete <head> tag full of data, you dynamically add your <meta> tags along with the rest of your data. See that's what I tried doing in the beginning but it didn't work cuz I guess the <meta> tag at the very top was getting read first, and after doing some reading I discovered that you have to get rid of the <head> tag at the top in order for the meta tags defined in your script to work Quote Link to comment Share on other sites More sharing options...
trq Posted February 12, 2011 Share Posted February 12, 2011 Obviously you still need to make sure your html is valid. Quote Link to comment Share on other sites More sharing options...
jamesjmann Posted February 17, 2011 Author Share Posted February 17, 2011 Obviously you still need to make sure your html is valid. It is but now I can't specify the meta tags for the main page. all of the pages with the news articles on them have their own unique tags, but now index.php shows up as "index.php" in the title bar. Here's the whole function: <?php //function for displaying only one item function displayOneItem($id) { global $db; /* query for item */ $query = "SELECT * FROM news WHERE id=$id"; $result = mysql_query ($query); $row = mysql_fetch_assoc($result); /* easier to read variables and * striping out tags */ $title = htmlentities ($row['title']); $news = nl2br (strip_tags ($row['body'], '<a><b><i><u>')); /* if we get no results back, error out */ if (mysql_num_rows ($result) == 0) { echo "This news article does not exist!\n"; return; } echo ("<title>DJSmiley.Net: $title</title>"); echo ("<meta name=\"Description\" content=\"$news\" />"); echo ("<link rel=\"image_src\" href=\"http://www.djsmiley.net/images/Logos/DJ Smiley Logo.jpg\" / >"); /* displays individual article user visits */ echo "<tr><td><strong><h2><a href=\"{$_SERVER['PHP_SELF']}" . "?action=show&id={$row['id']}\">$title</a></h2></strong> <em>posted</em> on {$row['date']} | by <strong>DJ Smiley</strong></td></tr>\n"; echo "<tr><td>"; echo stripslashes($news); echo "</td></tr>\n"; echo "</table>\n"; echo "<br>\n"; echo ("</table>\n<table width=\"100%\" border=\"0\"> <tr> <td width=\"6%\"><a href=\"{$_SERVER['PHP_SELF']}" . "?action=show&id={$row['id']}\"><img src=\"images/Icons/Comment/2.png\" width=\"20\" height=\"20\" class=\"fltlft2\"/></a>$comment_row[0]</td> <td width=\"13%\"><!-- FreeTellaFriend BEGIN --> <a href=\"http://www.freetellafriend.com/tell/\" onclick=\"window.open('http://www.freetellafriend.com/tell/?option=email&heading=Tell+A+Friend&bg=14&url=http%3A%2F%2Fhttp://www.djsmiley.net/index.php?action=show&id={$row['id']}', 'freetellafriend', 'scrollbars=1,menubar=0,width=435,height=500,resizable=1,toolbar=0,location=0,status=0,left='+(screen.width-435)/2+',top='+(screen.height-500)/3);return false;\"><img alt=\"Tell a Friend\" src=\"http://serv1.freetellafriend.com/s14.png\" border=\"0\" /></a> <!-- FreeTellaFriend END --></td> <td width=\"81%\"><span class=\"st_twitter_hcount\" st_url=\"http://www.djsmiley.net/index.php?action=show&id={$row['id']}\" displayText=\"Tweet\"></span><span class=\"st_facebook_hcount\" st_url=\"http://www.djsmiley.net/index.php?action=show&id={$row['id']}\" displayText=\"Share\"></span><span class=\"st_email_hcount\" st_url=\"http://www.djsmiley.net/index.php?action=show&id={$row['id']}\" displayText=\"Email\"></span><span class=\"st_sharethis_hcount\" st_url=\"http://www.djsmiley.net/index.php?action=show&id={$row['id']}\" displayText=\"Share\"></span></td> </tr> </table>"); /* now show the comments */ displayComments($id); } ?> This displays each article echoing their name in the title bar, but how can I reconstruct it (as an if statement, possibly?) so that IF one article is NOT being displayed, the title echos the <title> tag I've specified for index.php? 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.