Help Generating Dynamic Page Titles

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
aweb
Forum Newbie
Posts: 1
Joined: Sun Nov 01, 2009 8:09 pm

Help Generating Dynamic Page Titles

Post by aweb »

I am having trouble figuring out the best way to implement dynamic page titles within my site. Currently, my header file looks like this:

Code: Select all

<title><?php if(isset($title)) { print $title; } else { print "other title goes here"; } ?></title>
And within the site pages I have defined

Code: Select all

$title "unique page title here"
 
However I have a categories.php that the 30 or so categories are pulled from, so I need a new way of generating the titles since the pages are all generated from this one file.

At the top of the categories.php the database connection file is included along with the header and to display the given category, the id is defined:

Code: Select all

$id=$_REQUEST['id'];
And if this helps, the category lists are generated later with the following:

Code: Select all

<?
                    $servcat=mysql_query("select * from We_ServiceCategory_tbl ");
                    if(mysql_num_rows($servcat)>0)
                    {
                        while($rscat=mysql_fetch_assoc($servcat))
                        {
                    ?>
                        <a href="categories.php?id=<? echo $rscat['Category_Id'];?>" ><? echo htmlentities($rscat['Category_text']);?></a>
Any ideas on what would be the easiest way for me to get this working?

Thanks
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Help Generating Dynamic Page Titles

Post by Christopher »

Do you want the title to contain all of the category names? If so, concatenate the title from each fetched row to the $title string.
(#10850)
guru2k9
Forum Newbie
Posts: 9
Joined: Fri Oct 30, 2009 6:24 am

Re: Help Generating Dynamic Page Titles

Post by guru2k9 »

Hi,

Is this a pure php code .
Then we can set using the file .Ie getting the url and the file name from the url.
Depending up on the file we have a dynamic title .

Thanks
Post Reply