I am trying to make the page title the same as the gallery title on my site. This is my method, but it doesnt work.

on the page after I call the title from the database:

$pageTitle = $row['title'];

//page title
$page = array();
$page['title'] = 'Gallery - $pageTitle';

Then in my header:

<title><?php echo $page['title'];?></title>

But my page title is just the url. How would I get this to work?

Recommended Answers

All 4 Replies

Member Avatar for diafol

You've got to use double quotes if you're enclosing a variable without using the catenator (.):

$page['title'] = "Gallery - $pageTitle";

Should work.

Alright, good to know. I will keep that in mind for future. But it still doesnt create the page title. Let me give more information on how this page works.

I have a page. view.php within that I have the include for the header, footer and within it I have this:

<? $p = $_GET['p'];
	if ($p)
	{
		$p = "minc/".$p.".php";
		
		if(file_exists($p))
		{
			include($p);	
		}
		else
		{
			echo "That page does not exist! ";
		}
	
	}
	else 
	{
		include('inc/home.php');
} ?>

This code calls on the photo gallery template which I am trying to gather the page title from.
the file in minc/".$p.".php"; is photo.php that has:

$page = array();
$page['title'] = "gallery - $pageTitle";

I have tried changing a few things to try and get it to come through but it still doesnt work.

Member Avatar for diafol
<?php
//use php full tag

 
//make sure it's actually set
	if (isset($_GET['p']) && !empty($_GET['p']))
	{
		$p = $_GET['p']; //I'd clean this though
                $p = "minc/".$p.".php";
 
		if(!file_exists($p))
		{
			echo "That page does not exist! ";	
		}
		else
		{
			include($p);
		}
 
	}
	else 
	{
		include('inc/home.php');
}
?>

Maybe? If not, ensure that your relative reference (minc/...) is correct for this page.

What do you mean by "$p = $_GET; //I'd clean this though"?

If your wondering why im using $p instead of $page, is because im trying to call

$page = array();
$page['title'] = "gallery - $pageTitle";

on the other page and didnt know if it somehow conflicted so I changed $_GET to $_GET, and it shortens my URL

And the Page title still didnt work. If it comes down to it I guess I will just use a generic one unless I can think of another way to get it to work.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.