[nycphp-talk] title display based on page view
Adam Maccabee Trachtenberg
adam at trachtenberg.com
Tue Feb 10 11:01:40 EST 2004
On Tue, 10 Feb 2004 yury at heavenspa.com wrote:
> Chris hrmm I guess I'm still 1/2 asleep. I'd like to help some pages get
> relevant titles based on which page is displayed. So the example is like so:
>
> i have 51 pages - each page is a state name : state.php
>
> i'd like to have 51 titles that have a few of the major cities from that
> state.
>
> I'd like the title to be displayed based on the state.php page.. I guess i
> could do a huge swtich/case, but was wondering if there is a smart/simple
> way..
Are you saying you have 51 distinct physical pages (new_york.php,
connecticut.php, etc.) and want to write a PHP function that looks at
the file name and can generate the correct HTML title? Or that you
have 1 physical page (state.php) and 51 "virtual" pages?
If you have the first, try placing something like this in a file
that's included in all pages:
$titles = array('new_york.php' => 'New York Title',
'connecticut.php' => 'Connecticut Title',
...);
$path_parts = pathinfo($_SERVER['PHP_SELF']);
$title = $titles[$path_parts['basename']];
...
print "<title>$title</title>";
However, what you should really do is switch to the second setup and
pull all content, including the title, out of a database based on a
passed in page name. That solve the title problem and generalizes the solution.
-adam
--
adam at trachtenberg.com
author of o'reilly's php cookbook
avoid the holiday rush, buy your copy today!
More information about the talk
mailing list