473,388 Members | 1,326 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

Custom Chaging Page Title with php

http://microstudios.co.cc/

I assume that this should be quite easy but i just cant figure this out at all... I'm trying to make it so that the title of the page changes depending on the page that is included into my base index.php.

i have things set up within the index.php so that i use this code
Expand|Select|Wrap|Line Numbers
  1.         <?php
  2.  
  3.             if (!isset($_GET['page'])) {
  4.             $page = "blog"; 
  5.             } else {
  6.             $page = $_GET['page'];
  7.             }
  8.  
  9.             include ("pages/".$page.".php");
  10.  
  11.         ?>
to include the various pages from my pages directory.

what i want to do is be able to have the viewer be able to browse to, say, the Games page and have that reflect in the title. like: MicroStudios - Games - Best Viewed In Firefox

the problem i keep mindlessly running into is that the include page is of course always rendered AFTER the page title has been set... every site i've browsed through did not have a solution other than javascript and i'd like to avoid that 'cause that causes SEO problems...
Jul 11 '10 #1
10 3165
zorgi
431 Expert 256MB
@StarWallace
$_GET['page'] is available immediately, simply use it for your title. I am not sure what is your issue here. Can you provide more code? Especially the part where your title is defined.
Jul 11 '10 #2
TheServant
1,168 Expert 1GB
Is your title a variable? It should be accessible throughout unless you're using a function?
Jul 11 '10 #3
Samishii23
246 100+
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. switch ( @$_GET['page'] ) {
  3.   case "":
  4.     include "blog.php"; break;
  5.   case "games":
  6.     include "games.php"; break;
  7.   }
  8. ?>
Jul 12 '10 #4
I had been trying to use something along the lines of

HEAD
Expand|Select|Wrap|Line Numbers
  1. <title>MicroStudios - <?php echo $title; ?> - Best viewed in Firefox</title>
INCLUDED BODY PAGE
Expand|Select|Wrap|Line Numbers
  1. <?php $title="About"; header($title); ?>
but that doesn't work because the included "About" page is loaded after the index.php has already declared the title.

i don't know php well enough to have any idea of what i'm doing right or wrong... so that's all i really know to tell you. I'm TRYING to set a custom title from within the included page... if that's possible...
Jul 12 '10 #5
Samishii23
246 100+
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. switch ( @$_GET['page'] ) {
  3.   case "":
  4.     include "blog.php";
  5.     $title = "blog"; break;
  6.   case "games":
  7.     include "games.php";
  8.     $title = "Games"; break;
  9.   }
  10. ?>
  11.  
  12. <title>MicroStudios - <?php echo $title; ?> - Best viewed in Firefox</title>
Jul 12 '10 #6
i'm not sure i understand how that would work... doesn't the <title> tag have to be set in the <head>?

and besides that i don't think it would work for everything i'm trying to do because sometimes i want to be able to take the title from other things in the page. For example, a specific blog post, i don't know the name of the post until it has been loaded so i can't pre set the title for that...

it would be nice if you would give some explanation on what your showing me to do with the code you posted... i don't know php very well yet, i still only know extremely basic stuff.

edit: also, because i only know such simple stuff... i don't know the difference between a variable and a function...
Jul 12 '10 #7
zorgi
431 Expert 256MB
can you give us intire code of your index.php?
Jul 12 '10 #8
Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2.  
  3.  
  4.  
  5. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> 
  6. <head>
  7.  
  8.  
  9.  
  10. <!-- <title>MicroStudios - <?php echo $title; ?> - Best viewed in Firefox</title>-->
  11. <meta content="text/php; " http-equiv="Content-Type"/>
  12. <meta content="all" name="audience"/>
  13. <meta content="global" name="distribution"/>
  14. <meta content="INDEX, FOLLOW" name="robots"/>
  15. <meta content="7 days" name="revisit-after"/>
  16. <meta content="MicroStudios is a freeware games website. All games are freeware and are made with a variety of programing languages." name="description"/>
  17. <meta content="MicroStudios, Micro, Studios, StarWallace, Robbi, Grabnar, Grabnar the Wanderer, Games, XPlay, X-play, GrabnarGames" name="keywords"/>
  18. <link rel="stylesheet" type="text/css" href="<?php echo $stylesheet;  ?>" />
  19. <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script>
  20. <script type="text/javascript" src="js/gradualfader.js"></script>
  21. <script type="text/javascript" src="slimbox/js/slimbox2.js"></script>
  22. <script type="text/javascript" src="js/reflection.js"></script>
  23. <script type="text/javascript" src="js/ddwindowlinks.js"></script>
  24. <link rel="stylesheet" href="slimbox/css/slimbox2.css" type="text/css" media="screen" />
  25.  
  26. </head>
  27.  
  28. <body>
  29. <!--[if lte IE 6]>
  30. It appears that you are using Internet Explorer 6 or earlier. This website may not function fully on any version of IE before IE7. We appologize for the trouble, please update your browser or try out <a href="http://firefox.com">Firefox</a>!
  31. <![endif]--> 
  32.     <div id="Top"> <!-- The top section containing the header image, the menu, and a possible ad -->
  33.         <img src="css/images/head.png" style="margin: 0px 0px 0px -20px;"> 
  34.  
  35.  
  36.         <div id="Menu">
  37.             <a href="index.php?">Blog</a> <b>|</b> <a href="index.php?page=games">Games</a> <b>|</b> <a href="index.php?page=examples">Examples</a> <b>|</b> <a href="index.php?page=about">About</a> <b>|</b> <a href="index.php?page=contact">Contact</a>
  38.         </div>
  39.  
  40.     </div>
  41.  
  42.     <div id="Content"> <!-- The content section holding a possible side bar and the main content -->
  43.  
  44.  
  45.  
  46.  
  47.         <?php
  48.  
  49.             if (!isset($_GET['page'])) {
  50.             $page = "blog"; // Default page
  51.             } else {
  52.             $page = $_GET['page'];
  53.             }
  54.  
  55.             include ("pages/".$page.".php");
  56.  
  57.         ?> 
  58.  
  59. </div>
  60.  
  61.  
  62.     <div id="Footer" > <!-- the footer for copyright text and other things -->
  63.     <a title="RSS Feed" target="_blank" href="/pages/blog/rss.php?number=10"><img src="/pages/blog/skins/images/rss_icon.gif" style="margin: 0px 0px -4px 0px; border-width:0;" title="Subscribe to MicroStudios' blog's RSS feed"border=0  /></a>
  64.     <a href="http://www.firefox.com/" target="_blank"><img src="http://i33.tinypic.com/w9gtgx.png" style="margin: 0px 0px -4px 0px; border-width:0;" alt="Firefox" title="I recommend Firefox for the best internet browsing experience"></a>
  65.     <b>Copyright © 2006 - 2010 MicroStudios. Some Rights Reserved.</b>
  66.     <a href="index.php?page=about#copyright"><img alt="Creative Commons License" style="margin: 0px 0px -4px 0px; border-width:0;" src="http://i50.tinypic.com/2dl3ibm.png" title="MicroStudios copyright information"/></a>
  67.     <a href='http://host-tracker.com/' target="_blank" onMouseOver='this.href="http://host-tracker.com/uptime-statistics/2894124/lvuc/";'><img style="margin: 0px 0px -4px 0px; border-width:0;" title="MicroStudios' total uptime" width='80' height='15' border='0' alt='online check' src="http://ext.host-tracker.com/uptime-img/?s=15&amp;t=2894124&amp;m=00.59&amp;p=Total&amp;src=lvuc" /></a><noscript><a href='http://host-tracker.com/' target="_blank">broadband speed test</a></noscript>        
  68.     </div>
  69. <script type="text/javascript">
  70. gradualFader.init() //activate gradual fader
  71. </script>
  72.  
  73. </body>
  74.  
  75. </html>
i hope that helps...
Jul 12 '10 #9
anyone? doesn't anyone know how to fix this?
Jul 14 '10 #10
zorgi
431 Expert 256MB
Samishii23 alredy answered your question.
Jul 14 '10 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: the wonderer | last post by:
This is an elementary question, but I've not been able to find the answer, so here goes: I am developing a site using php. I have the html header information in a file that I include in all the...
6
by: Don Grover | last post by:
How can I get the page title into an variable to handle in my asp. Don
2
by: Benny Raymond | last post by:
How would you go about custom drawing the title bar of a form? I'd like to change it so that I can add different colors to my title and also change how the close button works (since I override it...
5
by: Maxim Izbrodin | last post by:
Hello For displaying page titles for my ASP.NET applications I use the following technique <title><%=BannerModule.PageTitle%></title where BannerModule.PageTitle is a public field of my user...
3
by: Craig Wilson | last post by:
How do I programmatically change the page title in ASP.Net In general, I need to get at the object model that gets access to the title property. best wishes,
14
by: Paul | last post by:
I want to set the page title and/or a form hidden field programatically through ASP.Net. I do not want to use something like... <% sTitle ="My Title" %> <html><title><%=sTitle%></title>..... ...
0
by: Abraham Andres Luna | last post by:
hello everyone, i just wanted to know if there was a workaround, or maybe it's just a bug. i have a master page: basepage.master <%@ Master %> <html> <head runat="server"> <title>CRM...
1
by: rn5a | last post by:
I am using the Title property of the Page class in the Page_Load event to set the title of the page so that the browser displays appropriate titles. <html> <head runat="server"> <script...
7
by: Marcolino | last post by:
Hi all, I need to add a custom button to title bar on a form in addition of a standard button. (Minimize/Maximize, close etc.) I need also to handle OnClick event of this button. I looked around...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.