Naming each php file in the title tag section

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
karey
Forum Newbie
Posts: 1
Joined: Sat Mar 21, 2009 1:46 pm

Naming each php file in the title tag section

Post by karey »

I'm probably not using the correct language but I will attempt to explain my problem.
We have not been able to figure out how to name each php file on our website in the title section so that when the page comes up it uses a different title than what is on the master template.

I don't understand php files very well and our web-design guy has not done any research to fix this problem.
Could someone look at one of our php files and see what we need to do.
Below is a sample of the section on the php file that I believe you need to look at. If not let me know what I need to show.

Thanks for the help,
Karey

//initialize an object of the class
$template=new patTemplate();

//set name of template file
$template->readTemplatesFromFile("templates/white_tmpl.html");

// set values for template variables
$template->addVar("master", "CENTER CONTENT", $content);

// set other variable values
$title=' - Feature page for “How the Right Brain Learns“';
$keyword='';

// replace placeholders with actual variable values
$template->addVar("master", "TITLE CONTENT", $title);
$template->addVar("master", "KEYWORD CONTENT", $keyword);
$template->addVar("master", "BANNER CONTENT", $banner);

// parse and display the template
$template->displayParsedTemplate("master");
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Re: Naming each php file in the title tag section

Post by JAB Creations »

If you haven't migrated to a database driven CMS or created your own then it's a painful process of having every single page have a static variable set.

If you have a variable in one page but then have the template elsewhere you'll likely benefit from using a PHP class.

my_page.php

Code: Select all

<?php
class cms{}
 
$cms = new cms();
$cms->set('title','page title goes here');
?>
_template_title.php

Code: Select all

<?php
echo '<title>'.$cms->title.'</title>'."\n";
?>
A PHP class variable once set can be accessed universally unlike a regular variable. You can also assign class variables arrays and such.

However this is ultimately a vain approach as I've used file-based templates long enough to know that relational database driven CMS is so much easier, at least once you have it up and running. :wink:
User avatar
php_east
Forum Contributor
Posts: 453
Joined: Sun Feb 22, 2009 1:31 pm
Location: Far Far East.

Re: Naming each php file in the title tag section

Post by php_east »

karey wrote: We have not been able to figure out how to name each php file on our website in the title section so that when the page comes up it uses a different title than what is on the master template.

// set other variable values
$title=' - Feature page for &#8220;How the Right Brain Learns&#8220;';
you picked the right spot i think ( patTemplate ). have an array of titles, then call up the relevant title for each php file
examples...

$titles['about_us.php']="ABOUT US";
$titles[contact_us.php']="CONTACT US";

you then find the page being accessed by looking $_SERVER['QUERY_STRING'];
and then assign the titles...

something like ...
$page = extract_page($_SERVER['QUERY_STRING']); // note extract page is an abstract function you will need to make to process to query to find which page is being accessed.

and then...

$title = $titles[{$page}];

and that would be it, patTemplate will do the rest.

hope i am making sense.
Post Reply