Using PHP to dynamically call a <title>description</title> to a webpage
Sorry, bit of a long one...
I'm having trouble inserting a unique HTML <title></title>
into a PHP page on my website. I'm a novice when it comes to PHP so would greatly appreciate any help or pointers you can give :).
Basically, I use a PHP script to display lots of "widgets" on my site. A visitor uses a drop-down menu to narrow the down the widgets to a single widget. The chosen widget, along with its unique attributes, are then displayed on a single page.
The problem is that the <title></title>
on the page are all the same; I need to dynamically call the <title></title>
according to the type of widget that is being displayed, along with the widget related attributes. So, when displayed to the user, the <title></title>
of the page should look like this:
<title>Buy a Blue Widget with Stripes</title>
The URL and querystring currently looks like this:
www.foo.com/fooscript.php?widgetType=blu&widgetPattern=stri
So, I need a call that will recognise widgetType=blu
references the word "Blue" and then insert tha开发者_如何学编程t word into a specific part of the <title></title>
tag.
Sorry its a bit of a long one, I've searched this but all I keep coming up with is WordPress tutorials.
<?php
if (isset($_GET['widgetType']))
{
switch($_GET["widgetType"])
{
case "blu":
$title = "Blue";
break;
default:
$title = NULL;
}
}
?>
<title><?php if(isset($title)) { echo $title." :: "; } ?> My cool website</title>
Explanation in the first comment, thank you @Smejko
<title>Buy a <?=htmlspecialchars($_GET['widgetType'])?> Widget with Stripes</title>
Matt you can change it too with Javascript
<script language="javascript">
document.title = "The new title goes here.";
</script>
精彩评论