Dynamic title errors

Reply

Join Date: Nov 2008
Posts: 54
Reputation: whitestream6 is an unknown quantity at this point 
Solved Threads: 0
whitestream6 whitestream6 is offline Offline
Junior Poster in Training

Dynamic title errors

 
0
  #1
Oct 29th, 2009
I'm trying to set dynamic titles on my pages with a switch statement, but can't get it to work.

Tried ifelse using code gleaned from Google but it didn't work.

I'm trying to get it so that all my pages' titles are able to be dynamically used from a value across the site stored in my main file - content.php

This is my code:
  1. <TITLE>My page title</TITLE>
  2.  
  3. <echo $mypagecontent ?>

Fairly basic, but the site is being developed on localhost anyway.

I would appreciate any help with this, as it's a new one for me!
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 539
Reputation: network18 is an unknown quantity at this point 
Solved Threads: 64
network18 network18 is offline Offline
Posting Pro
 
0
  #2
Oct 30th, 2009
try this and try to modify accordingly -
  1. <?
  2. //content is the array of titles which comes from the content.php page or the entire code can be put in the content.php
  3. $content = array('title1 - This is the Homepage','title2 -Find new friends','title3 - Get your visa cleared now','title4 - bark about your wife here','title5 - Dont have kids yet','some other page');
  4.  
  5. $arr = explode('/',$_SERVER['PHP_SELF']);
  6.  
  7. $current_page = $arr[count($arr)-1];
  8. //list your pages here
  9. $pages = array("1=>index.php","2=>friends.php","3=>nicks.php","4=>rent.php","5=>test.php");
  10. for($i = 0; $i<count($pages);$i++)
  11. {
  12. if($pages[$i] == trim($current_page))
  13. $pages_index = $i;
  14. else $pages_index = 6;
  15. }
  16. //This will echo the title
  17. echo $content[pages_index];
  18. ?>
ask,if you stuck up somewhere.
"The discipline of writing something down is the first step towards making it happen."

follow me on twitter
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 12
Reputation: rokape is an unknown quantity at this point 
Solved Threads: 1
rokape rokape is offline Offline
Newbie Poster

Another way to do it

 
0
  #3
Oct 30th, 2009
Another way would be to have a content.php stored with the following code:

  1. <?php
  2.  
  3. // Get pagename
  4. $page = $_GET['page'];
  5. if(!$page) $page = "home";
  6.  
  7. // Start pages
  8.  
  9. // Home page
  10. $pagetitle[home] = "Welcome to our site!";
  11. $pagecontent[home] = "We are glad you found our site!<br><font color='green'>Please have a browse through our pages.</font>";
  12.  
  13. // About us page
  14. $pagetitle[aboutus] = "A little about us";
  15. $pagecontent[aboutus] = "We are a small company located in the UK which specialise in SEO.";
  16.  
  17. // 404 Error page
  18. $pagetitle[notfound] = "Error 404";
  19. $pagecontent[notfound] = "The page you requested could not be found. (<b>".$page.")</b>";
  20.  
  21. // Set 404
  22. if(!isset($pagetitle[$page])) $page = "notfound"; // Incase of 404
  23.  
  24. // Display page
  25. //************
  26. // Instead you could include a template file?
  27. //************
  28. echo "<h1>";
  29. echo $pagetitle[$page];
  30. echo "</h1>";
  31. echo $pagecontent[$page];
  32.  
  33. ?>

You could use page IDs if you want but names look better.

Hope this helps

Josh
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 54
Reputation: whitestream6 is an unknown quantity at this point 
Solved Threads: 0
whitestream6 whitestream6 is offline Offline
Junior Poster in Training
 
0
  #4
27 Days Ago
Do arrays have to be numbered automatically, or can they be like array[pagetitlename.php]?
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 12
Reputation: rokape is an unknown quantity at this point 
Solved Threads: 1
rokape rokape is offline Offline
Newbie Poster
 
0
  #5
27 Days Ago
What I did there was an array but not a very good one. It's just vars for the element of the array.

They have to be strings though, no dots or special characters... correct me if i'm wrong.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 54
Reputation: whitestream6 is an unknown quantity at this point 
Solved Threads: 0
whitestream6 whitestream6 is offline Offline
Junior Poster in Training
 
0
  #6
27 Days Ago
This is the variable for the episode titles:
  1. $phptitle = "<NAME OF PROGRAMME>";

However, I have to manually change it for every page and add it as:
  1. <?php
  2. $phptitle = "test";
  3. ?>

which is this further down the page:
  1. <title>TV Episode Guide: PROGRAMME NAME: <?echo $phptitle ?></title>

I would like to know how to get it so that I can change it dynamically per page, whilst still using the echo variable.

Thanks
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 12
Reputation: rokape is an unknown quantity at this point 
Solved Threads: 1
rokape rokape is offline Offline
Newbie Poster
 
0
  #7
27 Days Ago
Explain in more detail, tell us about your project.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 54
Reputation: whitestream6 is an unknown quantity at this point 
Solved Threads: 0
whitestream6 whitestream6 is offline Offline
Junior Poster in Training
 
0
  #8
27 Days Ago
Originally Posted by rokape View Post
Explain in more detail, tell us about your project.
It is an episode guide for TV programmes, with the data stored in php variables.
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 12
Reputation: rokape is an unknown quantity at this point 
Solved Threads: 1
rokape rokape is offline Offline
Newbie Poster
 
0
  #9
27 Days Ago
Basicly...

  1. <?php
  2. $pagetitle = 'home'; // Set the default title...
  3. $thisepisode = 'Home with the family'; // Your episode name?
  4.  
  5. // Overwrite the $pagetitle
  6. if($thisepisode) $pagetitle = $thisepisode;
  7.  
  8. // Done
  9.  
  10. ?>

That would work
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 1,010
Reputation: ardav will become famous soon enough ardav will become famous soon enough 
Solved Threads: 130
ardav's Avatar
ardav ardav is offline Offline
Veteran Poster
 
-1
  #10
27 Days Ago
This is straightforward if your data is in DB (or file for that matter).
If you have just the one episode.php file and get the relevant programme via querystring and $_GET variable.

The structure of your data will be the key consideration.

If in a DB:

programmes table
id (PK)
page_title (varchar, 200?)
page_description (text)
page_keywords (text)
programme_title (varchar, 200?)
programme_contents (text)
programme_image (varchar, 100?)
programme_trailer_url (e.g. YouTube/Other id)
(other fields like main actors, director, production_company, year, etc)

The "page_" fields just get data to place into the HEAD area of the page. Perhaps "page_title" could be doubled up with "programme_title".

Using a DB may be useful as you could set up a WYSIWYG text editor (e.g. Spaw2/Yahoo!/FCKEditor/TinyMCE) to save this data.

Hand-coding hundreds of variables and placing them in a single file is probably asking for trouble.

The beauty of the DB is that you can search programmes by 'tag' (keywords) or category etc. You can also list programmes from the DB and create relevant links with the id in the querystring:

  1. $output = "<ul>";
  2. while(){
  3. $output .="\n\t<li><a href=\"episode.php?prog_id={$row['id']}\"></a>{$row['title']}</li>";
  4. }
  5. $output .="\n</ul>";
  6.  
  7. ...more code...
  8.  
  9. echo $output;

The querystring will then pass the relevant 'id' via $_GET['prog_id'] to the episode.php page. Then just query the DB to get the whole row - before the DTD. Then fill in your 'placeholder variables'.
Dunna letta dem afool ya - duh reppa sistema is da evil. INDETERMINACY is alive anda wella - force a duh issue.
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



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

©2003 - 2009 DaniWeb® LLC