PDA

View Full Version : Appearance of title tags (HELP PLEASE !)



jason1971
08-15-2008, 05:13 AM
HI everyone,
I have a classifieds website, usual sort of thing, books, dvds etc.. which all appear fine in the title tag along with my website name.

But how can I get the title to change
instead of saying:- Books For Sale | mywebsitename.com

I would like it to say New and used before Books for sale, I have tried just adding that to my title tag but it just stays there all the time, and I only want it to appear when a category is chosen. I have added below what my title tag looks like, to see what I am on about
<title><?= $catname ?> <?= $a1[CompanyName ] ?> <?= $catsl[subcatname] ?> <?= $mysubcatname ?> | Free UK classifieds Ad's in .mywebsite.com </title>

Hope you understand what im on about

Hope to hear off somebody soon, before my brain explodes

Jason - jasehunt33@aol.com

Chris
08-16-2008, 01:09 PM
If you want it to conditionally appear you need a conditional statement

if($catname != ""){
$title = "title with text":
}else{
$title = "default title";
}

echo "<title>".$title."</title>";

What is does is say "if catname is not blank, it has a value, then use this title, otherwise, use this other title"

Todd W
08-17-2008, 12:04 AM
If you want it to conditionally appear you need a conditional statement

if($catname != ""){
$title = "title with text":
}else{
$title = "default title";
}

echo "<title>".$title."</title>";

What is does is say "if catname is not blank, it has a value, then use this title, otherwise, use this other title"

If you are going to do that you may as well put the variable inside the double quotes.

Use single quotes if you don't plan to put variables inside... this tells PHP there are no variables inside (and if you put them in there it wont process them)... this is the faster way to have php process it. (Most likely negligible unless you are doing a ton of variables... none the less good tid-bit to know.) The same holds true when setting variables, etc.

I may have to run some speed test comparisons on 1 entire page of 'echos' and var setting just to see ;) I`m a geek!! LOL

deathshadow
08-20-2008, 06:29 PM
Use single quotes if you don't plan to put variables inside...
It is traditionally faster in most interpreted languages, though I'm uncertain how much of an effect it has upon PHP - You can get the same type of boosts by not constantly popping in and out of code parsing mode by not doing the constant <?php do one thing ?><b><?php do something else ?> rubbish. (this I did my own tests and found it was inside a loop only about a 2% speed difference over 1000 iterations, but hey every little bit helps)

I also prefer singles because I do my html attributes as doubles - therein I'm less likely to have to escape any quotes.

Likewise I'd not drop out of the echo, because again that's a parsing mode change, so I'd do that:

echo 'title'.($catname!='' ? 'title with text' : 'default title').'</title>';

Unless of course there were more than two conditions, which might make a switch faster than a compare even with changing parsing mode.