Help - Search - Members - Calendar
Full Version: Dynamic Page Title
Pixel2Life Forum > Help Section > PHP, ASP, MySQL, JavaScript and other Web/Database Programming Help
NextExile
A site I did not build but now am in charge of uses php require methods to assemble the header, content and footer.

As I understand, this prevents it from having different page titles. So i have 2 questions.

1) How can i utilize php to change the title depending on which content page gets loaded in? Content is drawn from php in documents purely, no database.

2) Whatever the method you recommend, will it help with SEO? Or will crawlers not be able to pick up titles like this?

Thank you in advance. I can provide any other necessary info.
Neil
Hi,

Could you please paste an example of how you display one of your pages, I am assuming it would be something like:

<?

require('header.php');

echo 'body content here';

require('footer.php');

?>

If that is the case an you not set a variable or constant before you require header.php which will be put into the <title> of your website code?

cheers
NDBoost
CODE
<?php
switch ($_GET['n']){
case 'home':
    $title = 'home title';
break;
case 'contact':
    $title = 'contact';
break;
}
?>
<title><?php echo $title; ?></title>


$_GET['n'] gets the page you're on, you'll need to replace n with whatever theyre using to load each page. The rest is a smiple switch that defines the content and then echos the content between a set of <title> tags..

If you post up the code for the PHP file that includes the header, content and footer all into one then I can help a lot more.
NextExile
Let me ask this quickly. These dynamic page titles, are they as effective as static ones in relation to SEO? Hence that's the whole point, it makes sense to figure that out first. Thank you guys.
rc69
Having a page title that better identifies the page that is currently being viewed is better for SEO. The only thing that would affect SEO is if it were a random page title (i.e. changes every refresh).
NextExile
QUOTE (rc69 @ Oct 26 2009, 11:04 AM) *
Having a page title that better identifies the page that is currently being viewed is better for SEO. The only thing that would affect SEO is if it were a random page title (i.e. changes every refresh).


That's not exactly what I meant. What I'm asking is, the simple html title vs the dynamic, php driven title, would they both be equally effective in relation to SEO or are the dynamic titles more difficult for web crawlers to pick up?

Here is a piece of navigation.

CODE


<li><a href="<?=$prefix?>facilities/" class="<?=($section=="facilities" ? "current" : "")?>" title="Product Ventures Facilities">Facilities</a>
<ul>
<li><a href="<?=$prefix?>facilities/technology_library.php">Technology Library</a></li>
<li><a href="<?=$prefix?>facilities/consumer_learning_center.php">Consumer Learning Center</a></li>
<li><a href="<?=$prefix?>facilities/creative_space.php">Creative Space</a></li>
<li><a href="<?=$prefix?>facilities/rapid_prototyping_shop.php">Rapid Prototyping Shop</a></li>
</ul>
</li>



Anything else? I've tried and so far nothing works.
NDBoost
go ahead and IM me on AIM/MSN.

MSN: m.devita@gmail.com
AIM: ThirdGenSup

NextExile,
here is a working example of my above code.. This is very remedial but it should be enough to get my point across.

You can view a working temporary example of it on my site here: http://t7labs.com/examples/dynamic_page_titles/
CODE
<?php
#Use a switch to monitor your ?n query string, it works much like an if/else statement.
switch ($_GET['n']){
default:
    $title = 'home title'; #define the home title
    $content = 'Home/default content'; #for this example instead of setting $content = 'content.php' were setting it to some text to be displayed.
break;
case 'contact':
    $title = 'contact title'; #define the contact title
    $content = 'Contact Page'; #for this example instead of setting $content = 'content.php' were setting it to some text to be displayed.
break;
case 'about':
    $title = 'about title'; #define the about title
    $content = 'About Page'; #for this example instead of setting $content = 'content.php' were setting it to some text to be displayed.
break;
}
?>
<title><?php echo $title; ?></title>
<p>Navigation: <a href="index.php">Home</a> | <a href="?n=contact">Contact</a> | <a href="?n=about">About</a></p>
<p>The Content document name can be set to a variable within the switch and then later down the line in the code included.. Like so.</p>
<?php
#Like previously mentioned, normally you would use a require_once("$content"); instead of an echo $content;. just make sure to set $content = to whatever the filename is you wish to include.
echo $content;
?>
Demonslay
There is really no difference if it is dynamically created. The end-user only sees HTML, be it a human through a browser, or a web-crawler. PHP outputs HTML, so that is all you are doing. The client parsing the HTML does not care, nor is it conventionally able to tell what produced it (HTTP headers might reveal what software the server is using, but still the client rarely cares about that); it just sees HTML, and does what it needs to do with it.

Compare these two bits of code.

CODE
<title>My Title</title>

<title><?php echo 'My Title'; ?></title>


Both will output the exact same HTML that anything will see, so there is no disadvantage. The advantage, as rc69 explained, is that your page will have a title more updated and fitting to that page, as opposed to the exact same title for every page, meaning it will help with SEO results.
rc69
Couldn't have said that better myself smile.gif
NDBoost
QUOTE (rc69 @ Oct 26 2009, 09:41 PM) *
Couldn't have said that better myself smile.gif


I agree, i apologize for not answering that part of the question.. i figured it was common knowledge now a days that having dynamic page titles would improve SEO.

There are many other ways of achieving what you're asking here.. my method is just one of them.
NextExile
Thanks for all the feedback guys. Much appreciated. victory.gif
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.