Forum

Thread tagged as: Question

List / Detail Page - Page Title

How do I change the <title> for List/Detail pages?

For example when someone lands on the page listing the title is just <title>Our Work</title> however when someone clicks on an item into the listing to show the 'detail' I want to change to <title>Our Work - [place] - [town]</title> where place and town are perch:content fields in the detail template

The <title></title> tag is in a layout 'global.header' and currently uses <?php perch_pages_title(); ?>

I want to be able to maintain <?php perch_pages_title(); ?> for the other pages on the website.

Neil Duddridge

Neil Duddridge 1 points

  • 6 years ago

Personally, I always do this:

In the list/detail page, I have something like:

$result = perch_content_custom("Region", array(
    "template"=>"/mytemplate.html",
    "filter"=>"slug",
    "match"=>"eq",
    "value"=>perch_get('myslug'),
    'skip-template' => true,
    'return-html' => true,
));
define('PAGE_TITLE',$result[0]['title']);

Then, in my header.php, I have:

<title><?echo PAGE_TITLE;?></title>

I would definitely be interested to know if there's a better way, though.

EDIT: In case it isn't obvious, this is assuming you're getting the list/detail with a URL like mypage.php?myslug=slug

Thanks Shane,

However, the title is part of the layout global.header currently set as

<title><?php perch_pages_title(); ?></title>

So do I have to create a separate header layout for the list/detail page?

I think you want this