Forum

Thread tagged as: Question, Problem

not returning a title in detail page of list and detail

Hi there

I am using a list detail with 2 pages... list is partners.php and detail is biographies.php - I have a global.header layout with the <?php perch_pages_title(); ?> and <?php perch_page_attributes(); ?> tags that go into the head of all my pages and return the title for all the pages in my site except the detail pages.

The code I am using is below, but I'm missing why the title will not show on the detail pages when it shows on all the other pages

Example links https://www.new.stork-may.com.server206.ukservers.net/partners.php (where the title is apparent at the top of the window) https://www.new.stork-may.com.server206.ukservers.net/biographies.php?s=john-mccarthy (where it does not appear)

Can you point to where I am going wrong

This is the global.header layout

<!DOCTYPE html>
<html lang="en">
    <head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, minimum-scale=1, initial-scale=1">
<meta name="author" content="">
<title><?php perch_pages_title(); ?></title>
    <?php perch_page_attributes(); ?>

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"><!-- Bootstrap core CSS -->
<link rel="stylesheet" href="">
<link rel="stylesheet" type="text/css" href="" />
    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
</head>

In the Perch admin on all the other (non detail) pages I can see where the SEO information is added (including a page title), but when i edit the detail pages there is only a 'region options' section, and nowhere to enter the description, keywords etc.

my detail template is

<div class="container-fluid topimagebar">
    <style type="text/css">
    .topimagebar {background-image: url(<perch:content id="background" type="image" label="Main header image" />)}
    </style>
<div class="wrapper ampersand">
<p class="mainquote">“<perch:content id="quote" type="textarea" size="s" label="Quote text" required="true" />”</p>
<p class="attribution"><perch:content id="title" type="text" label="Employee Name" required="true" title="true" />, <perch:content id="role" type="text" label="Employee Role" required="true" /> </p>
</div><!-- wrapper ends -->
</div><!-- container ends -->
<div class="container-fluid">
<div class="wrapper"><div class="thirds" style="height: 0; margin: 0; padding: 0;"></div>
<div class="twothirds">
<h1><perch:content id="title" /></h1>
<h2 style="margin: -17px 0 10px 0;"><perch:content id="role" /></h2>
<p><perch:content id="phone" type="text" label="Your main phone number" required="true" help="Enter your  phone number here" /><br>
<a href="mailto:<perch:content id="email" type="text" label="Your email address" required="true" />?subject=Email enquiry from Stork & May website"><perch:content id="email" /></a></p>
</div>
<div class="thirds">
<ul class="rslides">
  <li><img src="<perch:content type="image" id="portrait" label="Employee Portrait" />" alt="Image of <perch:content id="title" />, <perch:content id="role" /> at Stork & May" /></li>
</ul>
</div><!--
--><div class="twothirds">
<hr class="hidemobile">
<h2>Biography</h2>
<perch:content id="biogtext" type="textarea" size="m" label="Main Biography Text" markdown="true" editor="markitup" />
<h2>Education</h2>
<perch:content id="educationtext" type="textarea" size="m" label="Education Text" markdown="true" editor="markitup" />
<h2>Experience</h2>
<perch:content id="experiencetext" type="textarea" size="m" label="Experience Text" markdown="true" editor="markitup" />
</div>
</div><!-- wrapper ends -->
</div><!-- container ends -->
<perch:layout path="global.partnerminusslug" />
<perch:content id="slug" for="title" type="slug" suppress="true" />

my list page (partners.php) is

<?php include('perch/runtime.php'); ?>
<?php perch_layout('global.header'); ?>
<body>
<?php perch_layout('global.nav'); ?>
<?php

     perch_content_create('biographies', array(
          'template'  => 'partners-detail.html',
          'multiple'  => true,
          'edit-mode' => 'listdetail',
     ));
?>
<?php perch_content('partners'); ?>
<?php perch_layout('global.footer'); ?>
</body>
</html>

my list page html template is

<script>
  $(function() {
    $(".rslides").responsiveSlides({
        speed: 2000,
        timeout: 5000,
        random: true,
        maxwidth: 800
      });
  });
</script>

<div class="container-fluid topimagebar">
    <style type="text/css">
    .topimagebar {background-image: url(<perch:content id="background" type="image" label="Main header image" />)}
    </style>
<div class="wrapper ampersand">
<p class="mainquote"><perch:content id="quote" type="text" label="Quote text" required="true" /></p>
<p class="attribution"><perch:content id="attribution" type="text" label="Quote attribution" required="false"  /></p>
</div><!-- wrapper ends -->
</div><!-- container ends -->

<div class="container-fluid">
<div class="wrapper">
<div class="twothirds bump"><h1><perch:content id="pagetitle" type="text" label="Page title" required="true" title="true" /></h1></div>
<div class="thirds">

<perch:layout path="global.slider" />

</div><!--

--><div class="twothirds">
<perch:content id="maintext" type="textarea" size="xs" label="Main Our partners intro text" markdown="true" editor="simplemde" />
<h2>Talk to one of us to find out more.</h2>
</div>
</div><!-- wrapper ends -->
</div><!-- container ends -->

<perch:layout path="global.partner" />

Where the 2 layouts in the template, global.partner and global.slider are in there to insert the php list code for 2 different regions on the page - one being an image slider and the other a list of names... these look like...

<?php
          perch_content_custom('biographies', array(
               'template' => 'partners-list.html',
          ));
?>

which returns

<perch:before>
<div class="container-fluid dark" style="padding: 0 20px;">
<ul id="partnerlist">
</perch:before>
<li><a href="biographies.php?s=<perch:content id="slug" type="slug" />"><perch:content id="title" /></a></li>
<perch:after>
</ul>
</div>
</perch:after>

and

<?php
          perch_content_custom('biographies', array(
               'template' => 'partners-slider.html',
          ));
?>

which returns

<perch:before>
<ul class="rslides">
</perch:before>
  <li><a href="biographies.php?s=<perch:content id="slug" type="slug" />"><img src="<perch:content id="portrait" />" alt="<perch:content id="name" />"></a></li>
<perch:after>
</ul>
</perch:after>

I am using the latest version of Perch

Perch: 3.0.10, PHP: 7.0.23, MySQL: 5.6.36, with PDO Server OS: Linux, cgi-fcgi Installed apps: content (3.0.10), assets (3.0.10), categories (3.0.10) App runtimes: <?php $apps_list = [ ]; PERCH_LOGINPATH: /perch PERCH_PATH: /home/users/uks87346/html/new.stork-may.com/perch PERCH_CORE: /home/users/uks87346/html/new.stork-may.com/perch/core PERCH_RESFILEPATH: /home/users/uks87346/html/new.stork-may.com/perch/resources Image manipulation: GD Imagick PHP limits: Max upload 128M, Max POST 128M, Memory: 256M, Total max file upload: 128M F1: 3b606135b33e6a102526838f4152a807 Resource folder writeable: Yes SCRIPT_NAME: /perch/core/settings/diagnostics/index.php REQUEST_URI: /perch/core/settings/diagnostics/ DOCUMENT_ROOT: /home/users/uks87346/html/new.stork-may.com HTTP_HOST: www.new.stork-may.com.server206.ukservers.net

Ben Read

Ben Read 0 points

  • 3 years ago

Hi Ben

If I've understood correctly then unfortunately <?php perch_pages_title(); ?> is only going to return the title of the page. So if you are on biographies.php then it's going to pull in the page title for that page, not the individual regions.

Because you have a header outside the template then you'll need to use something like a combination of perch_layout and perch_page_attributes_extend to pass variables from the regions back into the <head> tag.

Hope this helps,

Kind regards

Jon

Hi Jon

Ah... so I misunderstood what <?php perch_pages_title(); ?> actually does

It's not 'looking' for (and then returning) the content from the perch id with title="true"- which is what I assumed it was doing.

Fine... I'll keep at it

cheers

Ben

I've rummaged around from an old project and found this that worked for me – please edit to suit your purposes if it helps.

You'll need to add content tags in your detail template for meta title and descriptions.

In your page:

if (perch_get('s')) {   
    $metaGrab = perch_content_custom('biographies', array(
        'skip-template' => 'true',
        'filter' => 'slug',
        'match' => 'eq',
        'value' => perch_get('s'),
        'count' => 1,   
     )); 

    perch_layout('global.header', array (
        'metaTitle' => $metaGrab[0]['metaTitle'],
        'metaDesc' => $metaGrab[0]['metaDescription'],
    ));
    }
    else {
            perch_layout('global.header');
    }   

In your head layout:

        if (isset($_GET['s']) & (perch_layout_has('metaTitle')))
        {    
             $title = perch_layout_var('metaTitle', true);
             $description = perch_layout_var('metaDesc', true);

            echo '<title>'.$title.'</title>'."\n";
            echo '<meta name="description" content="'.$description.'"/>';               
        }

You can juice this up by using perch_page_attributes_extend but this is quick and dirty!

Good luck!

Jon

Many thanks... I'll have a go!

B