| | |
Dynamic Title
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
Every page in the system is grabbed into index.php.
For each page i'd like the title to change according to the page it's on, this can be set manually within each page we want to send.
My question is what would be the most effective method of updating the title each time a new page is viewed.
eg: $common->setTitle($title);
Is what i have in mind, but how would index.php know what the current title is so it can do '<title><?php echo getTitle(); ?>' or something along those lines.
Thanks in Advance.
Drag
For each page i'd like the title to change according to the page it's on, this can be set manually within each page we want to send.
My question is what would be the most effective method of updating the title each time a new page is viewed.
eg: $common->setTitle($title);
Is what i have in mind, but how would index.php know what the current title is so it can do '<title><?php echo getTitle(); ?>' or something along those lines.
Thanks in Advance.
Drag
GardCMS :: Open Source CMS :: Gardcms.org
Hello.
You can do it that way:
index.php
functions.php :
If you want to include page downloads.php for example - > index.php?page=downloads.
This is just a simple guess and you can find other way.
- Mitko Kostov
You can do it that way:
index.php
php Syntax (Toggle Plain Text)
<?php include("functions.php"); $title = checkPage($_GET['page']); ?> <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title><?php echo $title; ?></title> </head> <body> <?php $page.=".php"; include($page); ?> </body> </html>
functions.php :
php Syntax (Toggle Plain Text)
<?php function checkPage($arg) { switch ($arg) { case "home": $title = "Home"; break; case "downloads": $title = "Downloads"; break; } return $title; } ?>
If you want to include page downloads.php for example - > index.php?page=downloads.
This is just a simple guess and you can find other way.
- Mitko Kostov
•
•
Join Date: May 2009
Posts: 1
Reputation:
Solved Threads: 0
this is a solution for have a title in each page?
or must write a title in head?
html Syntax (Toggle Plain Text)
<html><head> </head> <body> <title>My site- article name</title> </body><html>
Last edited by peter_budo; May 29th, 2009 at 6:52 am. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
•
•
Join Date: Jul 2009
Posts: 1
Reputation:
Solved Threads: 0
php Syntax (Toggle Plain Text)
<?php switch($_GET['page']) { default: include('src/home.php'); break; case "Home": include('src/home.php'); break; case "Register": include('src/register.php'); break; } ?>
this is the code im using and it works for me change the include() stuff and if you save this as index go to
http://yourweb.com/name?page=case
like mine is 127.0.0.01/?page=home i recommend using it as index so u dont need to type in the extra index.php?page blah blah blah BUT dont send them to http://yourweb.com just like that you have to send them to http://yourweb.com/?page=home or theres gonna be a wierd glitch still workin on it
Last edited by peter_budo; Jul 19th, 2009 at 5:06 am. Reason: Keep It Spam Free - Do not spam, advertise, plug your website, or engage in any other type of self promotion.
//EDIT
Apologies, I posted this and only then saw the original thread creation date, after it was resurrected.
//EDIT
Are you using include files or a db to store your pages?
If using a db, you could have something like:
PAGE_DATA
id
page_title
page_keywords
page_description
(other head fields)
page_content
If using files, just place the head data at the top of the include file:
Obviously you'd need to include this file above your DTD and echo out the variables in the appropriate place.
If you're using a CMS / online text-editor to create your page content, the $page_content variable could be the contents of that file.
There are quite a few ways to do this.
BTW
If you're creating a system like WordPress, the db solution could be useful coz you could have an url like
The beauty of your method is that you've just got 1 'template':
Sorry if I'm stating the obvious and telling granny how to suck eggs.
Apologies, I posted this and only then saw the original thread creation date, after it was resurrected.
//EDIT
Are you using include files or a db to store your pages?
If using a db, you could have something like:
PAGE_DATA
id
page_title
page_keywords
page_description
(other head fields)
page_content
If using files, just place the head data at the top of the include file:
PHP Syntax (Toggle Plain Text)
$title = '...'; $keywords = '...'; $description = '...'; (other head variables) $page_content = '...';
Obviously you'd need to include this file above your DTD and echo out the variables in the appropriate place.
If you're using a CMS / online text-editor to create your page content, the $page_content variable could be the contents of that file.
PHP Syntax (Toggle Plain Text)
$page_content = file_get_contents('content/welshrugby_2009.html');
There are quite a few ways to do this.
BTW
If you're creating a system like WordPress, the db solution could be useful coz you could have an url like
index.php?article=7 . Your $_GET['article'] variable would then be used to search the db for the page. Otherwise, you may be left using a string as a parameter in the querystring for a particular filename: index.php?article=welshrugby_2009 which would then include the welshrugby_2009.php file (and possibly get a welshrugby_2009.html through the file_get_contents as mentioned above, depending on how you're creating the content).The beauty of your method is that you've just got 1 'template':
PHP Syntax (Toggle Plain Text)
...(do php include based on $_GET variable)... <html> ...dtd... <head> <title><?php echo $title;?></title> ...more of the same for other head elements... </head> <body> ...get common php header... ...get common navbar... ...get common sidebar(s)... <?php echo $content;?> ...get common php footer... </body> </html>
Sorry if I'm stating the obvious and telling granny how to suck eggs.
Last edited by ardav; Jul 19th, 2009 at 3:44 pm.
"...the woods would be a very silent place if no birds sang except for the best"
All opinions count - unless you're a serial downvoter.
F'enw i yw Mr. Blaidd. Byddwch yn ofalus - dwi'n cnoi.
All opinions count - unless you're a serial downvoter.
F'enw i yw Mr. Blaidd. Byddwch yn ofalus - dwi'n cnoi.
![]() |
Similar Threads
- help with dynamic memory (C++)
- dynamic combo load problems (PHP)
- Page title (ColdFusion)
- ASP.NET / C# Dynamic Control (ASP.NET)
- Urgent.....Dynamic Changes.... (JavaScript / DHTML / AJAX)
Other Threads in the PHP Forum
- Previous Thread: How to embed youtube player in php mail function
- Next Thread: Tips on Operator & Method Overloading: Your way of doing it
| Thread Tools | Search this Thread |
apache api array beginner binary body broken buttons cakephp checkbox class cms code cron curl database date date/time display dynamic ebooks echo email error file files folder form forms function functions global google href htaccess html image include insert ip javascript joomla limit link list login mail mediawiki menu mlm msqli_multi_query multiple mycodeisbad mysql number oop parameter paypal pdf php phpincludeissue phpmyadmin problem query radio random recursion remote script search seo server sessions sms soap source sp space speed sql static subdomain syntax system table tag tutorial update upload url validator variable vbulletin video web webdesign white wordpress xml youtube





