Jump to content

Recommended Posts

I am changing up my site a little more to make it simple to edit but only changing one file. So I have the include for the header and that all works. But I want each page to have a different title. So I tried

 

$title = 'Title Name' under the include file. and set the title to $title and it doesn't work. Does anyone know how to do this?

Link to comment
https://forums.phpfreaks.com/topic/133133-solved-php-title/
Share on other sites

This is a common issue of envoking CMS because generally you use a sandwhich principle to include a footer/header around a dynamic content section.

 

The trick to doing this, this is one easy way.

 

1) Make a separate include_once page called titles which has an array that looks like

<?php
$titles['index.php'] = "Home Page";
$titles['about.php'] = "About Us";
?>

Include it above your header include and draw your titles of this combined with $_SERVER['PHP_SELF'];

 

Link to comment
https://forums.phpfreaks.com/topic/133133-solved-php-title/#findComment-692391
Share on other sites

like

<?php
require_once("titles.php");
require_once("header.php");
?>

 

In header.php

<?php
echo "<head>";
echo "<title>Mysite: ".$titles[$_SERVER['PHP_SELF']]."</title>";
echo "</head>";
?>

Should get that title var

 

 

You could put the titles in the header file but down the line you may say hey lets add DB backend to it and then its already separated and easy to build into it

Link to comment
https://forums.phpfreaks.com/topic/133133-solved-php-title/#findComment-692418
Share on other sites

I actually encountered this error in writing my CMS about 6 months ago and it made me restructure my whole process.  Mine uses a database to pull everything so what I needed to do was first query for the content and title of the given page and then get the header/footer content then send header-content-footer to the browser for rendering.  Once you figure it out its simple but I knocked my head on a wall for a week on making it work how I wanted.

Link to comment
https://forums.phpfreaks.com/topic/133133-solved-php-title/#findComment-692425
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.