Dynamic Title

Reply

Join Date: Apr 2007
Posts: 136
Reputation: dr4g is an unknown quantity at this point 
Solved Threads: 5
dr4g's Avatar
dr4g dr4g is offline Offline
Junior Poster

Dynamic Title

 
0
  #1
Jul 17th, 2007
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
GardCMS :: Open Source CMS :: Gardcms.org
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 142
Reputation: MitkOK is an unknown quantity at this point 
Solved Threads: 12
MitkOK's Avatar
MitkOK MitkOK is offline Offline
Junior Poster

Re: Dynamic Title

 
0
  #2
Jul 17th, 2007
Sorry for the double post, please some mod to delete this.

- Mitko Kostov
Last edited by MitkOK; Jul 17th, 2007 at 3:56 pm.
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 142
Reputation: MitkOK is an unknown quantity at this point 
Solved Threads: 12
MitkOK's Avatar
MitkOK MitkOK is offline Offline
Junior Poster

Re: Dynamic Title

 
0
  #3
Jul 17th, 2007
Hello.

You can do it that way:

index.php

  1. <?php include("functions.php");
  2. $title = checkPage($_GET['page']);
  3.  
  4. ?>
  5. <?xml version="1.0" encoding="UTF-8"?>
  6. <!DOCTYPE html
  7. PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  8. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  9. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  10. <head>
  11. <title><?php echo $title; ?></title>
  12. </head>
  13. <body>
  14. <?php $page.=".php";
  15. include($page);
  16. ?>
  17. </body>
  18. </html>

functions.php :

  1. <?php
  2. function checkPage($arg) {
  3. switch ($arg) {
  4. case "home":
  5. $title = "Home";
  6. break;
  7. case "downloads":
  8. $title = "Downloads";
  9. break;
  10. }
  11. return $title;
  12.  
  13. }
  14. ?>

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
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 1
Reputation: constantin_ro is an unknown quantity at this point 
Solved Threads: 0
constantin_ro constantin_ro is offline Offline
Newbie Poster

Re: Dynamic Title

 
0
  #4
May 28th, 2009
this is a solution for have a title in each page?
  1. <html><head>
  2. </head>
  3. <body>
  4. <title>My site- article name</title>
  5. </body><html>
or must write a title in head?
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.
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 1
Reputation: iamjoseph951 is an unknown quantity at this point 
Solved Threads: 0
iamjoseph951 iamjoseph951 is offline Offline
Newbie Poster

Re: Dynamic Title

 
0
  #5
Jul 18th, 2009
  1. <?php
  2. switch($_GET['page']) {
  3. default:
  4. include('src/home.php');
  5. break;
  6. case "Home":
  7. include('src/home.php');
  8. break;
  9. case "Register":
  10. include('src/register.php');
  11. break;
  12. }
  13. ?>

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.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 986
Reputation: ardav will become famous soon enough ardav will become famous soon enough 
Solved Threads: 128
ardav's Avatar
ardav ardav is offline Offline
Posting Shark

Re: Dynamic Title

 
0
  #6
Jul 19th, 2009
//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:

  1. $title = '...';
  2. $keywords = '...';
  3. $description = '...';
  4. (other head variables)
  5. $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.

  1. $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':

  1. ...(do php include based on $_GET variable)...
  2. <html>
  3. ...dtd...
  4. <head>
  5. <title><?php echo $title;?></title>
  6. ...more of the same for other head elements...
  7. </head>
  8. <body>
  9. ...get common php header...
  10. ...get common navbar...
  11. ...get common sidebar(s)...
  12. <?php echo $content;?>
  13. ...get common php footer...
  14. </body>
  15. </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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC