Jump to content

How to include variable meta data in header


Lassie

Recommended Posts

I want to include variable mata data im my header by including the varaiablee from a page specific file.

in the header i include a file to determine the page title and by passing this as a variable include the relevant page specific information.

How do I write the include and echo the varaibles?

The include  include('./metadata/$title_metadata.php');

Header function

<?php
function do_html_header()
{
include ('./includes/title.inc.php');
?>
<!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" lang="en" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Authorbank<?php if (isset($title)) echo"&#8218;{$title}";?></title>
<meta name="description"content=<?php echo"{$description};?>/>
<meta name="keywords"content=<?php echo"{$keywords}";?>/>
<link href="/authorbank/includes/layout.css" media="screen"
rel="stylesheet" type="text/css" />
<link href="/authorbank/includes/menu.css" media="screen" rel="stylesheet" type="text/css />"	
<?php	
}

title.inc.php
[code]
<?php
$title = basename($_SERVER['SCRIPT_NAME'], '.php');
$title = str_replace('_', ' ', $title);
if ($title == 'index') {
  $title = 'home';
  }
$title = ucwords($title);
include ('./metadata/$title_metadata.php')
?>

meta data
[code]
<?php
$description="Authorbank  Connecting Authors with Publishers";
$keywords="publishing, Finding a Publisher, Getting Published,writers, authors, submitting a book proposal";
?>

[/code]

[/code]

Link to comment
Share on other sites

Your html is in a function, the variables taht you use inside taht function need to be passed to it

 

function example() {
return $foo;
}
$foo = 'test';
echo example();//nothing printed

function example($foo) {
return $foo;
}
$foo = 'test';
echo example($foo);//test printed

Link to comment
Share on other sites

Ok this is the header function

i include title.inc at the top.

title.inc determines the page title we are on and the opens the relevant meta data file.

This is where i need help to build the path to open the file and read the variables so they can be put in the meta tags.

Header

function do_html_header()
{
include ('./includes/title.inc.php');
?>
<!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" lang="en" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Authorbank<?php if (isset($title)) echo"&#8218;{$title}";?></title>
<meta name="description"content=<?php echo{'$description'};?>/>
<meta name="keywords"content=<?php echo{'$keywords'};?>/>
<link href="/authorbank/includes/layout.css" media="screen"
rel="stylesheet" type="text/css" />
<link href="/authorbank/includes/menu.css" media="screen" rel="stylesheet" type="text/css />"	
<?php	
}

Title.inc.php

<?php
$title = basename($_SERVER['SCRIPT_NAME'], '.php');
$title = str_replace('_', ' ', $title);
if ($title == 'index') {
  $title = 'home';
  }
$title = ucwords($title);
//Build file path
$path = './metadata/';
$path = $path.$title;
//Read contents of file
$data=fopen($path.$title,'r') or die('Cant open file');
$theData = fread($data,filesize($myFile));
fclose($data);
?>

The meta data is in ./metadata/home.php for the first page.

<?php
$description="Authorbank  Connecting Authors with Publishers";
$keywords="publishing, Finding a Publisher, Getting Published,writers, authors, submitting a book proposal";
?>

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.