Jump to content

How To Get Dynamic Page Title To Work With Dynamic Pages?


designer76

Recommended Posts

I am trying to figure out how to get my page titles to change based off of using dynamic pages. The problem that I am having is that my dynamic pages are being called after my header, so my title and keywords are not setting or changing based on which pages are being called dynamically. Someone somewhere else suggested a method where the $_GET takes the page name and uses it as the title, but that won't work for me because I want specific information displayed for each pages title.

 

Can anyone help me with this? I have provided example code below. Thanks in advance for any help given!

 

EXAMPLE PAGE TO BE INCLUDED IN INDEX FILE:

$title = "Title Information That I Want To Display.";

<div class="test">
<div class="junk"></div>
</div>

 

INDEX FILE:

header
(included in the head section of the header is:) <title><?php echo $title ?></title>

<?php include ('include/header.php'); ?>

$a = $_GET['a'];
$b = $_GET['b'];

if (!$a)
$a = "home";

if (!$b)
$b = "a";

$path = "$b/".$a.".php";

include ($path);

<?php include ('include/footer.php'); ?>

 

 

Link to comment
Share on other sites

Variables don't have values until the code that assigns them a value has been executed. You are going to need to reorganize your logic if you want it to work.

 

Simplest method would be to stop looking at php as a way to copy/paste headers, footers, and content that makes up a page and look at it as a way to build and output content where you want it on a page.

 

Put the code that determines $path and the include ($path) statement as one of the first things on the page (after any other initialization logic.) The code being included by $page should consists of some business logic (the $title variable) and presentation logic (the content or even a template.) You then simply echo the content that was built at the appropriate point on the page, but the business logic that defines what the page means is available to everything on the page because it was included first.

Link to comment
Share on other sites

Old guy musing...

 

Perhaps:

 

var1 = array of possible titles

var2 = this page (a get or post or session var  that says with which page/header we are dealing)

include header.php (inside that -- <title><?PHP echo $var[$var2]; ?></title>  )

Link to comment
Share on other sites

Variables don't have values until the code that assigns them a value has been executed. You are going to need to reorganize your logic if you want it to work.

 

Simplest method would be to stop looking at php as a way to copy/paste headers, footers, and content that makes up a page and look at it as a way to build and output content where you want it on a page.

 

Put the code that determines $path and the include ($path) statement as one of the first things on the page (after any other initialization logic.) The code being included by $page should consists of some business logic (the $title variable) and presentation logic (the content or even a template.) You then simply echo the content that was built at the appropriate point on the page, but the business logic that defines what the page means is available to everything on the page because it was included first.

 

OK, I tried doing something like this below and my title is working, but my layout is screwed up, What am I doing wrong?

 


$a = $_GET['a'];
$b = $_GET['b'];

if (!$a)
$a = "home";

if (!$b)
$b = "a";

$path = "$b/".$a.".php";

include ($path);


<?php include ('include/header.php'); ?> (included in the head section of the header is:) <title><?php echo $title ?></title>

<?php echo $path; ?>

<?php include ('include/footer.php'); ?>

Link to comment
Share on other sites

An example (http://nstoia.com/demo/demo_header/)

 

index.html

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<!-- Created on May 8, 2010 12:43:23 PM -->

<html xmlns="http://www.w3.org/1999/xhtml">
   <head>
      <title>
         origin
      </title>
      <meta name="GENERATOR" content="Arachnophilia 5.4"/>
      <meta name="FORMATTER" content="Arachnophilia 5.4"/>
   </head>

   <body bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#800080" alink="#ff0000">
		This simply is where your page choice is comming from. It could be a form or <br>
		links (that pass the what_page via url) etc<p>
		For purposes of this example we will use radio buttons.<p>
      <form action="page1.php" method="post">
			<input type="radio" name="what_page" value="Home Page"/> Home<br>
			<input type="radio" name="what_page" value="Movie Page"/> Movies<br>
			<input type="radio" name="what_page" value="Music Page"/> Music<br>
			<input type="radio" name="what_page" value="Contact Page"/> Contact<br>
			<input type="submit" value="Submit"/>
		</form>

   </body>
</html>

 

page1.php

<?PHP
session_start();
if(!isset($_POST['what_page'])){
$what_page = "Home Page";
}else{
$what_page = $_POST['what_page'];
}
include('header.php');
?>

 

header.php

<?PHP
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<!-- Created on May 8, 2010 12:43:23 PM -->

<html xmlns="http://www.w3.org/1999/xhtml">
   <head>
      <title>
         <?PHP echo $what_page; ?>
      </title>
      <meta name="GENERATOR" content="Arachnophilia 5.4"/>
      <meta name="FORMATTER" content="Arachnophilia 5.4"/>
   </head>

   <body bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#800080" alink="#ff0000">
put the content for the appropriate <?PHP echo $what_page; ?> here
</body>
</html>
<?PHP
?>

 

make sense?

 

Link to comment
Share on other sites

drop the include($path), thats your content and you are putting it before and after your header.

 

 

HTH

Teamatomic

The problem when I do that is that it is echoing the path and not the content. So it is literally echoing a/landing.php in the html and not the content inside landing.php.

 

litebearer, the problem with your method is that I may end up having a ton of pages, which would mean that form/whatever is going to get pretty long. I kinda prefer the route I am going if I can get it to work properly. I do appreciate your help!

Link to comment
Share on other sites

Based on your code example form the first post in the thread -

 

Some page to be included -

<?php
$title = "Title Information That I Want To Display.";

$main_content = <<<EOT
<div class="test">
<div class="junk"></div>
</div>
EOT;
?>

 

index.php

<?php
$a = $_GET['a'];
$b = $_GET['b'];
if (!$a)
$a = "home";
if (!$b)
$b = "a";
$path = "$b/".$a.".php";
include ($path);
include ('include/header.php');
echo $main_content;
include ('include/footer.php');
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.