GiGalo Posted April 9, 2012 Share Posted April 9, 2012 I followed this tutorial http://www.dynamicdrive.com/forums/showthread.php?t=28260. Everything is working fine but I cannot get the title on selected page to display. It will only display "Home" for the title on every page. I need this to say the correct title of selected page Quote Link to comment https://forums.phpfreaks.com/topic/260647-template-titles/ Share on other sites More sharing options...
KevinM1 Posted April 9, 2012 Share Posted April 9, 2012 Show us your code so we can see if there are any differences between it and the tutorial code. Quote Link to comment https://forums.phpfreaks.com/topic/260647-template-titles/#findComment-1335850 Share on other sites More sharing options...
GiGalo Posted April 9, 2012 Author Share Posted April 9, 2012 Here is my index page:  <?php include '../scrp/menu.php'; ?> <!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> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <meta name="description" content="dogue de bordeaux,dogue de bordeaux for sale,dogue de bordeaux stud,dogue de bordeaux stud service,dogue de bordeaux puppies,french mastiff,french mastiff stud,french mastiff puppies,french mastiffs,french mastiffs for sale, dogue de bordeaux mastiff,dogue de bordeaux mastiffs,dogue de bordeaux mastiffs for sale,dogue de bordeaux mastiff stud service,dogue de bordeaux mastiff puppies,dogue de bordeaux for sale Ohio,puppies for sale,stud service,bordeaux dogue,dogue de bordeaux" /> <meta name="keywords" content="Big Time Bordeaux, Bordeaux, Big Time" /> <meta name="author" content="Big Time Bordeaux" /> <link rel="stylesheet" type="text/css" href="../style/newStyle.css" media="screen" /> <script language="javascript" src="../scrp/jquery.min.js"></script> <title><?php echo $title; ?> </title> <script type="text/javascript">     $(function(){         $('.smallie').click(function(){             var url = $(this).attr("src");             url = url.replace("thumbs", "imgs"); // i assume your image names in thumbs and imgs folders are the same, hence I change just folder name             document.images.biggie.src = url;         });     });     </script> </head> <body>  <div id="wrapper">   <div id="header">    <?php include '../includes/header.php'; ?>   </div> <!-- end #header -->   <div id="nav">   <?php generateMenu(); ?>   </div> <!-- end #nav -->   <div id="content">    <?php     $default = 'home'; //Whatever default page you want to display if the file doesn't exist or you've just arrived to the home page.     $page = isset($_GET['p']) ? $_GET['p'] : $default; //Checks if ?p is set, and puts the page in and if not, it goes to the default page.     $page = basename($page); //Gets the page name only, and no directories.     if (!file_exists('scrps/'.$page.'.php'))  { //Checks if the file doesn't exist       $page = $default; //If it doesn't, it'll revert back to the default page       //NOTE: Alternatively, you can make up a 404 page, and replace $default with whatever the page name is. Make sure it's still in the inc/ directory.      }         include('scrps/'.$page.'.php'); //And now it's on your page!   ?>   </div> <!-- end #content -->   <div class="sidebar">    <h3>Navigation</h3>    <?php    generateMenu();    include '../includes/sidebar.php';    ?>   </div> <!-- end #sidebar -->   <div id="footer">    <?php include '../includes/footer.php'; ?>   </div> <!-- end #footer -->  </div> <!-- End #wrapper --> </body> </html>   Here is my separate menus generator page: <?php $menu = array(); $menu['home'] = 'Home'; $menu['about'] = 'About'; $menu['gallery'] = 'Gallery'; $menu['contact'] = 'Contact'; //Add in the format of: $menu['page name'] = 'Page Title'; $title='Home'; //Default title function generateMenu()  {   global $menu,$default,$title;    $p = isset($_GET['p']) ? $_GET['p'] : $default;   foreach ($menu as $link=>$item)  {     $class='';     if ($link==$p)  {       $class=' class="selected"';       $title=$item;     }     echo '<a href="?p='.$link.'"'.$class.'>'.$item.'</a>';   }  } ?> Quote Link to comment https://forums.phpfreaks.com/topic/260647-template-titles/#findComment-1335853 Share on other sites More sharing options...
dcro2 Posted April 9, 2012 Share Posted April 9, 2012 A simple way could be to add if(!empty($_GET['p']) && !empty($menu[$_GET['p']])) $title = $menu[$_GET['p']]; anywhere before the title gets echoed, like at the bottom of menu.php. Quote Link to comment https://forums.phpfreaks.com/topic/260647-template-titles/#findComment-1335855 Share on other sites More sharing options...
GiGalo Posted April 9, 2012 Author Share Posted April 9, 2012 I added at the end exactly like you said and it work like a champ. Thank you very much for that Quote Link to comment https://forums.phpfreaks.com/topic/260647-template-titles/#findComment-1335858 Share on other sites More sharing options...
dcro2 Posted April 9, 2012 Share Posted April 9, 2012 No, you have to put it outside the function. Just make a new line before the end tag (?>) and insert it there. Quote Link to comment https://forums.phpfreaks.com/topic/260647-template-titles/#findComment-1335861 Share on other sites More sharing options...
GiGalo Posted April 9, 2012 Author Share Posted April 9, 2012 I figured that out. I edited my last post while you were posting . Thank you again!! Quote Link to comment https://forums.phpfreaks.com/topic/260647-template-titles/#findComment-1335863 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.