Forum

Thread tagged as: Question

Title and meta tags for list/detail setup

Hi, I'm using Layout Variables and Page Attributes to add editable unique titles and meta tags for each page of a site. However, where I've used a list/detail setup I am stuck on how to create editor editable titles and meta descriptions for the detail pages. I've seen a similar thread https://forum.grabaperch.com/forum/08-15-2015-page-details-and-metatags but I'm still a bit lost.

My global.top.php at the moment:

<title><?php perch_layout_var('title'); ?></title>
  <?php
      perch_page_attributes(array(
          'template' => 'seo.html'
      ));
  ?>

For list/detail setup I'd like the title from portfolio-item.html template

<h1><perch:content id="title" type="text" label="Title" required="true" title="true" /></h1>

output as 

<title>Title of the Detail Page</title>

Any help on this and also how to allow editors to add meta descriptions etc. for a list/detail setup whilst using Layouts much appreciated.

Louise Shearer

Louise Shearer 0 points

  • 6 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

  1. Create a template for your meta fields

  2. Copy the fields also into your list/detail master template, adding the suppress="true" attribute so that they don't output on the page.

  3. In the head of your document, display the detail mode just as you do in the body, but this time set the template to be your new meta template.

Thanks Drew. With your help I've now set up editable titles and meta tags for detail pages.

My detail.php has this in the head

<?php
  perch_content_custom('Portfolio', array(
        'page' => '/portfolio/index.php',
        'template' => 'meta.html',
        'filter' => 'slug',
        'match' => 'eq',
        'value' => perch_get ('s'),
        'count' => 1,
       ));
  ?>

The rest of the site pages use global.top.php Layout, currently:

<title><?php perch_layout_var('title'); ?></title>
  <?php
      perch_page_attributes(array(
          'template' => 'seo.html'
      ));
  ?>

Ideally though I'd like to use my global.top.php Layout for list/detail parts of the site too. How would I go about this?

Drew McLellan

Drew McLellan 2638 points
Perch Support

You should be able to pass the result into the layout using layout variables.

https://docs.grabaperch.com/docs/layouts/variables/

If it helps anyone, I am using this:

projects.php

  <?php
    // PROJECT DETAIL SEO

    // get project detail data
    $content = perch_content_custom('Projects', array(
      'filter' => 'slug',
      'match' => 'eq',
      'value' => perch_get('s'),
      'count' => 1,
      'skip-template' => 'true',
    ));

    // header include (with overrides)
    perch_layout('global/header', [
      'page-title' => $content[0]['title'],
    ]);
  ?>

header.php

  <title>
    <?php
      // title overrides
      if (perch_layout_has('page-title')) {
        perch_layout_var('page-title');
      } else {
        perch_pages_title();
      }
    ?>
  </title>

If an override exists, output that - otherwise fall back to perch_pages_title(). Same can be done for any number of fields/meta/etc.