Forum

Thread tagged as: Question, Blog

How to add blog post page titles

I'm very confused about how to get the page title to appear as the current blog post title. Also, how to create a meta description for a blog post.

Im using a global header (also used by the blog). Normal pages display the page title and meta description fine, but the blog home page and post pages don't display them and they aren't available in the admin.

Perch: 3.0.9, PHP: 7.0.1, MySQL: mysqlnd 5.0.12-dev - 20150407 - $Id: 7e72f9690b1498a1bead7a637c33a831c0d2f655 $, with PDO
Server OS: Linux, cgi-fcgi
Installed apps: content (3.0.9), assets (3.0.9), categories (3.0.9), perch_blog (5.5.1)
App runtimes: <?php $apps_list = array( 'content', 'categories', 'perch_blog', );
PERCH_LOGINPATH: /perch
PERCH_PATH: /var/sites/0/05creative.com/public_html/perch
PERCH_CORE: /var/sites/0/05creative.com/public_html/perch/core
PERCH_RESFILEPATH: /var/sites/0/05creative.com/public_html/perch/resources
Image manipulation: GD
PHP limits: Max upload 100M, Max POST 100M, Memory: 128M, Total max file upload: 100M
F1: 3b606135b33e6a102526838f4152a807
Resource folder writeable: Yes
DOCUMENT_ROOT: /var/sites/0/05creative.com/public_html
HTTP_HOST: 05creative.com
REQUEST_URI: /perch/core/settings/diagnostics/
SCRIPT_NAME: /perch/core/settings/diagnostics/index.php

post.html...

<article class="h-entry">

    <div class="post-header">
        <div class="row padded featured-img">
            <div class="small-7 small-centered columns post-title">
                <h1 class="font-two">
                    <perch:blog id="postTitle" type="text" label="Title" required="true" size="xl autowidth" order="1" value="true" />
                </h1>
            </div>
        </div>
    </div>
    <div class="row padded featured-img">
        <div class="small-12 medium-7 small-centered medium-centered columns post-title">

            <perch:if exists="image"><img class="blog-list-img" src="<perch:blog id="image" type="image" crop="true" width="365" height="246"/>" alt="<perch:blog id="postTitle" />" /></perch:if>
        </div>
        <div class="small-12 medium-7 small-centered medium-centered columns post-title">
            <div class="blog-description e-content">
                <perch:blog id="postDescHTML" type="textarea" label="Post" order="2" editor="redactor" html="true" size="xxl autowidth" required="true" />
            </div>
        </div>
        </div>
    </div>
     <div class="row padded">
        <div class="small-12 medium-7 small-centered medium-centered columns">

            <div class="blog-author-share">
                <p class="blog-author small-12 medium-6 columns">BY <perch:blog id="author" type="text" label="Author" order="2"    markdown="true" size="m" required="true" /><br>
                <time class="dt-published" datetime="<perch:blog id="postDateTime" type="date" label="Date" time="true" format="Y-m-d H:i:s" divider-before="Publishing" />">
                <perch:blog id="postDateTime" type="date" time="true" format="%d %B %Y" /> 
                </time>
                </p>
            </div>
                <p class="meta">
                    <perch:categories id="categories" set="blog" label="Categories" display-as="checkboxes" suppress="true">
                        <a href="archive.php?cat=<perch:category id="catSlug" type="slug" />" class="p-category">
                            <perch:category id="catTitle" type="text" />
                        </a>
                    </perch:categories>
                </p>
        </div>
</article>

<perch:blog id="image" type="image" width="500" height="500" crop="true" suppress="true" />
Chris James

Chris James 0 points

  • 3 years ago

Chris,

this:

<perch:blog id="postTitle" type="text" label="Title" required="true" size="xl autowidth" order="1" value="true" />

needs to be this:

<perch:blog id="postTitle" type="text" label="Title" required="true" size="xl autowidth" order="1" />

you had a value="true" attribute on the tag, which is likely over-riding the "Title"

Does this solve it?

Thanks Robert but it makes no difference. I think Im probably missing something more fundamental but cant get to the bottom of what it is!

have you added <perch:showall /> to your html template to see that the data you're looking to output is available in this instance, and that your using the proper namespace and id?

Wait, Do you want the html <title>blog-postTitle</title>?

Yes - I want the page title that appears in the browser tab. The one you normally add in the page attributes for other pages

Is your global header in a layout?

If so you can pass this info into the layout using <?php perch_layout('global.header',['pageTitle'=>'My Fancy Post Title Here']); ?> Then use an if/else to replace the page title in the global header...

<?php
    if (perch_layout_has('pageTitle')) {
        perch_layout_var('pageTitle');
    }else{
        perch_pages_title();
    }
?>

Robert Ketter said:

Is your global header in a layout?

If so you can pass this info into the layout using <?php perch_layout('global.header',['pageTitle'=>perch_blog_post_field(perch_get('s'), 'postTitle']); ?> Then use an if/else to replace the page title in the global header...

<?php
   if (perch_layout_has('pageTitle')) {
       perch_layout_var('pageTitle');
   }else{
       perch_pages_title();
   }
?>

Updated the code above, but also giving you another idea here: <title><?php perch_blog_post_field(perch_get('s'), 'postTitle'); ?></title>

it's not using layouts, no. Can I adapt this to work with my setup?

I currently have this in my header.php

<title><?php perch_pages_title(); ?> | 05Creative*</title>

which produces page titles fine, but not for the blog posts

yes...

Chris James said:

I currently have this in my header.php

<title><?php perch_pages_title(); ?> | 05Creative*</title>

which produces page titles fine, but not for the blog posts

<title><?php (perch_blog_post_field(perch_get('s'), 'postTitle', true)) ? perch_blog_post_field(perch_get('s'), 'postTitle') : perch_pages_title(); ?> | 05Creative*</title>

Excellent - that seems to have done the trick.

I cant thank you enough Robert - you're a life saver :)

I see you got it working... :)