Forum

Thread tagged as: Question

Adding Meta to a Details page

Hi,

I've followed this Solution to set up a List with Details page: https://solutions.grabaperch.com/architecture/how-do-i-create-list-detail-pages

Now I'm a little stumped to how to set up the meta title and description for the details pages.

I'm using a layout var in my global.above to give me the option of using the page attributes or meta with perch custom :


<title><?php perch_layout_var('title'); ?></title> <?php if (perch_layout_var('meta', true)) { echo perch_layout_var('meta', true); } ?> <?php if (perch_layout_var('page_att', true)) { echo perch_page_attributes(); } ?>

Then in the template of my details page I have tried the following to return the id of 'short-headline' as the title from the template 'case-study-content.html', and get the meta from another template:

<?php perch_layout('global.above', array(

        'title' => perch_content_custom(array(
            'template' => 'case-study-content.html',
            'filter' => 'slug',
             'match' => 'eq',
             'value' => perch_get('short-headline'),
        ), true), 

        'meta'  => perch_content_custom(array(
                'template' => 'content_meta.html',
                'filter' => 'slug',
                'match' => 'eq',
                'value' => perch_get('s'),
            ), true), 

        ));
?>

I admit I'm not really sure what I'm doing here. Am I on the right track?

Sarah Evans

Sarah Evans 0 points

  • 6 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Is short-headline on your query string?

No it's a text field, would I filter on that id then to return it?

Drew McLellan

Drew McLellan 2638 points
Perch Support

The perch_get() function pulls a value from the query string on the URL, so that's not what you want here.

Are you trying to get a single value from the region? You can use the skip-template option for that.

Thanks Drew. I'm (hopefully) getting closer.

I have this, wanting to get the content from the id 'short-headline' which is on the /what-we-do.php page with the template case-study-content.html from within the Case Studies Region.

 'title' => perch_content_custom('Case Studies',array(
            'page' => '/what-we-do.php',
            'template' => 'case-study-content.html',
            'filter' => 'short-headline',
            'skip-template' => 'true',
        ), true), 
Drew McLellan

Drew McLellan 2638 points
Perch Support

Try this:

$result =  perch_content_custom('Case Studies',array(
            'page' => '/what-we-do.php',
            'skip-template' => 'true',
        ), true);

if ($result) {
    echo $result[0]['short-headline'];
}

That seems to return the first Region items 'short-headline' rather than the one needed for its Details page

Drew McLellan

Drew McLellan 2638 points
Perch Support

Ok, then just add your filter:

           'filter' => 'slug',
                'match' => 'eq',
                'value' => perch_get('s'),

If anyone has a similar question this is what I ended up with:

 'title' => perch_content_custom('Case Studies',array(
    'page' => '/what-we-do.php',
    'template'=>'case-study-title.html',
    'filter' => 'slug',
    'match' => 'eq',
    'value' => perch_get('s'),

        ), true), 

I duplicated the content I wanted into its own template