1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

html <title> and php

Discussion in 'HTML, Graphics & Programming' started by cremo, 15 Oct 2009.

  1. cremo

    Hitman

    Joined: 12 Jun 2003

    Posts: 899

    Location: Wicklow, Ireland

    how's it going folks.

    i've been given a task to cleaning up a website that was written about 3-4 years ago.

    the site structure looks like this.

    Code:
    html
    +----about
               +----history
                          +----index.php (site.com/about/history/)
               +----index.php (site.com/about/)
    +----contact
               +----index.php (site.com/contact/)
    +----downloads
               +----index.php (site.com/downloads/)
    
    etc.etc.
    
    now each folder (about, history etc.) has the exact same html code at the top for example.

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
      	<head profile="http://gmpg.org/xfn/11">
    	  <?php include("../../i/metas.php"); ?>
    	  <title>Development Education Explored | DevelopmentEducation.ie</title>	
    	 		<link rel="stylesheet" type="text/css" href="../../c/titles.css" media="screen" />
    	  	<link rel="stylesheet" type="text/css" href="../../c/all.css" media="screen"/>
    	  	<link rel="stylesheet" type="text/css" href="../../c/other.css" media="screen" />
    	  	<link rel="stylesheet" type="text/css" href="../../j/niftyCorners.css" media="screen" />
    	  	<link rel="stylesheet" type="text/css" href="../../c/print_all.css" media="print"/>
    	  	<link rel="stylesheet" type="text/css" href="../../c/print_other.css" media="print" />
    	  	
    	  	<script type="text/javascript" src="../../j/swfobject.js"></script>
    		<script type="text/javascript" src="../../j/niftycube.js"></script>
    	    <script type="text/javascript">
    	    window.onload=function(){
    	    	Nifty("div.green","normal");
    	    	Nifty("div.dkgrey","normal");
    	    	Nifty("div.ltgrey","normal");
    	    }
    	    </script>
    		
    	</head>
    	
    	<body>
    			<a name="top"></a>
    				<div id="cnt">
    				
    				
    				
    				
    						 <div id="top"><?php include("{$pa}i/logo.php"); ?>
    									
    						 
    						 
    								<div id="topmenu">
        								<ul>
        										<li class="on"><a href="../../about/">About</a></li>
    												<li><a href="../../partners/">Partners</a></li>
    												<li><a href="../../glossary/">Glossary</a></li>
    												<li><a href="../../contact/">Contact</a></li>
    												<li><a href="http://www.developmenteducation.ie/sitemap">Site Map</a></li>
                        </ul>
    								<?php include("{$pa}i/googlesearch.php"); ?>
    								</div>
    								<div id="menu">
    										 
    									<ul>
    <li class="list1"><a id="item1" href="../../" title="Home">Home</a></li>
    <li class="list2"><a id="item2" href="../../issues/" title="Issues and Topics">Issues &amp; Topics</a></li>
    <li class="list3"><a id="item3" href="../../resources/" title="Links and Resources">Links &amp; Resources</a></li>
    <li class="list4"><a id="item4" href="../../galleries/" title="Cartoons and Photos">Cartoons &amp; Photos</a></li>
    <li class="list5"><a id="item5" href="../../action/" title="Taking Action">Taking Action</a></li>
    <li class="list6"><a id="item6" href="../../book/" title="80:20 The Book">80:20 The Book</a></li>
    <li class="list7"><a id="item7" href="../../teachers/" title="Teachers and Educators">Teachers &amp; Educators</a></li>
    <li class="list8"><a id="item8" href="../../shop/" title="Shop">Shop</a></li>
                        				</ul>
    								
    								</div>
    						 </div>
    

    i want to be able to create a header.php file that includes all this html code, but takes the directory name of that folder and uses that directory name inside the title tag of the html.
     
  2. fishfishfish

    Gangster

    Joined: 30 Jan 2008

    Posts: 468

    ...
     
  3. marc2003

    Capodecina

    Joined: 6 Feb 2004

    Posts: 20,198

    Location: England

    PHP:
    <title><?php echo dirname($_SERVER["SCRIPT_NAME"]); ?></title>
    edit: or maybe this would look a little nicer (untested - might be some typos :p)

    PHP:
    <title>yoursite.com | <?php echo str_replace('/',' | ',ucfirst(dirname($_SERVER["SCRIPT_NAME"]))); ?></title>
    should give...

    yoursite.com | About | History
     
    Last edited: 15 Oct 2009
  4. cremo

    Hitman

    Joined: 12 Jun 2003

    Posts: 899

    Location: Wicklow, Ireland

    thanks that works if put into every index.php file, but i want to do is have something like this.


    header.php
    PHP:
    <? /* ================================================= */
    //echo  $_SERVER['PHP_SELF'];
    $c 0$pa "";
    $filename explode("/"$_SERVER['PHP_SELF']); 
    $filename2 "";

    ?>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
          <head profile="http://gmpg.org/xfn/11">
          <? include("i/metas.php"); ?>
          <title>site.com  <?php echo str_replace('/',' | ',ucfirst(dirname($_SERVER["SCRIPT_NAME"]))); ?></title>
                
                  
              <link rel="stylesheet" type="text/css" href="c/all.css" />
              <link rel="stylesheet" type="text/css" href="c/home.css" />
              <link rel="stylesheet" type="text/css" href="c/titles.css" />
              
              <link rel="stylesheet" type="text/css" href="j/niftyCorners.css"><script type="text/javascript" src="http://www.developmenteducation.ie/j/swfobject.js"></script>
            <script type="text/javascript" src="j/niftycube.js"></script>
            <script type="text/javascript">
            window.onload=function(){
                Nifty("h5","normal");
            }
            </script>
                
                
                
                
                   <script language="JavaScript" type="text/javascript">
                    <!--
                    // this function opens a new window each time it is invoked
                    function imageWindow(image_path, winWidth, winHeight, copyright_owner, title)
                    {  
                        OpenWindow=window.open("", title,"width=" + winWidth + ",height=" + winHeight + "toolbar=no,scrollbars=no,menubar=no");
                        OpenWindow.document.write("<html><title>" + title + "<\/title>");
                        OpenWindow.document.write("<body style='margin: 0; padding: 0; font-family: Arial, Tahoma, sans-serif; font-size: 12px; color: #666;'>");
                        OpenWindow.document.write("<img src='" + image_path + "'>");
                        OpenWindow.document.write("<center>Copyright &copy; " + copyright_owner + "</center>");
                        OpenWindow.document.write("<\/BODY>");
                        OpenWindow.document.write("<\/HTML>");
                        
                        OpenWindow.document.close();
                        // self.name="main"
                    }
                    function animWindow()
                    {  
                        OpenWindow=window.open("", "","width=450,height=380,toolbar=no,scrollbars=no,menubar=no");
                        OpenWindow.document.write("<html><title>DevelopmentEducation.ie - 100 People Animation<\/title>");
                        OpenWindow.document.write("<body style='margin: 0; padding: 0; font-family: Arial, Tahoma, sans-serif; font-size: 12px; color: #666;'>");
                            OpenWindow.document.write("<OBJECT classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0' WIDTH='438' HEIGHT='350' id='final' ALIGN=''><PARAM NAME=movie VALUE='final.swf'> <PARAM NAME=quality VALUE=high><PARAM NAME=bgcolor VALUE=#FFFFFF><EMBED src='final.swf' quality=high bgcolor=#FFFFFF  WIDTH='438' HEIGHT='350' NAME='final' ALIGN='' TYPE='application/x-shockwave-flash' PLUGINSPAGE='http://www.macromedia.com/go/getflashplayer'></EMBED></OBJECT>"); 
                        OpenWindow.document.write("<\/body>");
                        OpenWindow.document.write("<\/html>");
                        
                        OpenWindow.document.close();
                        // self.name="main"
                    }
                    //-->
                    </script>
                
                
                
                
                
            
        </head>
        
        <body id="home">
        
                    <div id="cnt">
                             <div id="top">
                                    <?php include("i/logo.php"); ?>
                                    <div id="topmenu">
                                        <ul>
                                                <li><a href="about/">About</a></li>
                                                    <li><a href="partners/">Partners</a></li>
                                                    <li><a href="glossary/">Glossary</a></li>
                                                    <li><a href="contact/">Contact</a></li>
                                                    <li><a href="http://www.developmenteducation.ie/sitemap">Site Map</a></li>
                        </ul>
                        <?php include("{$pa}i/googlesearch.php"); ?>
                                    
                                    </div>
                                    <div id="menu">
                                             
                                        <ul>
    <li class="list1On"><a id="item1On" href="./" title="Home">Home</a></li>
    <li class="list2"><a id="item2" href="issues/" title="Issues and Topics">Issues &amp; Topics</a></li>
    <li class="list3"><a id="item3" href="resources/" title="Links and Resources">Links &amp; Resources</a></li>
    <li class="list4"><a id="item4" href="galleries/" title="Cartoons and Photos">Cartoons &amp; Photos</a></li>
    <li class="list5"><a id="item5" href="action/" title="Taking Action">Taking Action</a></li>
    <li class="list6"><a id="item6" href="book/" title="80:20 The Book">80:20 The Book</a></li>
    <li class="list7"><a id="item7" href="teachers/" title="Teachers and Educators">Teachers &amp; Educators</a></li>
    <li class="list8"><a id="item8" href="shop/" title="Shop">Shop</a></li>
                                        </ul>
                                    
                                    </div>
                             </div>

    so that no matter where you are in the directory tree the title will look like this

    site.com | about | history
    site.com | home
    site.com | downloads

    and at the top of every index.php page in every directory i just do this.

    PHP:
    include ('header.php');
     
    Last edited: 15 Oct 2009
  5. marc2003

    Capodecina

    Joined: 6 Feb 2004

    Posts: 20,198

    Location: England

    no. you put it in header.php file and include that in each "content" file exactly as you described. it works. i'm guessing you haven't actually tried it yet...
     
  6. cremo

    Hitman

    Joined: 12 Jun 2003

    Posts: 899

    Location: Wicklow, Ireland

    aye but the header.php file the links to css files are all screwed as it doesn't keep the paths :(
     
  7. zetec452

    Sgarrista

    Joined: 15 Sep 2003

    Posts: 9,454

    Alter the paths then... :p
     
  8. cremo

    Hitman

    Joined: 12 Jun 2003

    Posts: 899

    Location: Wicklow, Ireland

    yeh but if they'll have to be different for every page.

    all css is in a folder called c.

    so for about/history to get at it it's ../../c/style.css
    but for about/ to get at it it's ../c/style.css

    is there's something gapingly obvious that i'm missing here, i'm really rusty on web programming.
     
  9. marc2003

    Capodecina

    Joined: 6 Feb 2004

    Posts: 20,198

    Location: England

    Code:
    /c/style.css
    
    will work from anywhere regardless of your folder structure.
     
  10. Smithy

    Wise Guy

    Joined: 9 Mar 2006

    Posts: 1,519

    Using root-relative links you can create a link relative to the website root no matter where you are within the site's structure.

    Using marc2003's code will work.

    http://www.motive.co.nz/glossary/linking.php