Forum

Thread tagged as: Question, Addons, Blog

Show date/time with postDateTime

Hi, I'm having trouble displaying the date and time of a post using postDateTime.

It seems that something like <perch:blog id="postDateTime" type="text" /> cannot be used on the perch/blog/post.php page. I'm also not able to use it on any of the templates that this page references, example perch/templates/blog/author.html

The only page it is working for me is in perch/templates/blog/post_in_list.html. Is there a reason why I can't use this in other templates.

Shawn North

Shawn North 0 points

  • 5 years ago
Rachel Andrew

Rachel Andrew 394 points
Perch Support

Can you show us your template and Diagnostics Report please?

Here I can use <perch:blog id="postDateTime" type="text" /> and it outputs the blog post date for each post in the blog index page.

<perch:before>
<ul class="list-inline meta-info">
    </perch:before>

        <!-- author -->
        <li>By <perch:blog id="authorGivenName" type="text" /> <perch:blog id="authorFamilyName" type="text" /></li>
        <!-- categories -->
        <li>In </li>
        <!-- post date -->
        <li>Posted <perch:blog id="postDateTime" type="text" /></li>
        <!-- comment count -->
        <li>Comments</li>

        <h2><a href="<perch:blog id="postURL" />" rel="bookmark" class="entry-title"><perch:blog id="postTitle" /></a></h2>
        <perch:if exists="image"><img src="<perch:blog id="image" type="image" width="50" height="50" crop="true" />" alt="<perch:blog id="postTitle" />" /></perch:if>
        <p class="entry-published date"><perch:blog id="postDateTime" format="%d %B %Y" /></p>
        <div class="description entry-summary">
        <perch:blog id="excerpt" type="textarea" textile="true" />
        <p>Comments: <perch:blog id="postCommentCount"/></p>
        </div>

<perch:after>
    </ul>
    <perch:if exists="paging">
        <div class="paging">
            Page <perch:blog id="current_page" /> of <perch:blog id="number_of_pages" />
            <perch:blog id="page_links" encode="false" />
            <perch:if exists="not_first_page">
                <a href="<perch:blog id="prev_url" encode="false" />">Previous</a>
            </perch:if>
            <perch:if exists="not_last_page">
                <a href="<perch:blog id="next_url" encode="false" />">Next</a>
            </perch:if>
        </div>
    </perch:if>
</perch:after>

But for the blog post page I want to include the post date in the side bar. The blog/post.php makes up this page using a number of references to files located in the perch/templates/blog folder.

Here for example I have a side bar that pulls in many of these templates. I added <perch:blog id="postDateTime" type="text" /> to the author.html template and the date does not show.

perch/templates/blog/author.html

<p><strong>Posted:</strong>
    <perch:blog id="postDateTime" type="text" />
</p>

<p><strong>Written by:</strong>
<a href="/blog/archive.php?author=<perch:blog id="authorSlug" type="text" />">
    <perch:blog id="authorGivenName" type="text" label="Given name" order="1" />  
    <perch:blog id="authorFamilyName" type="text" label="Given name" order="2" /></a>
</p>        

<perch:if exists="author_image">
    <img src="<perch:blog id="author_image" type="image" suppress="true" label="Image" width="240" height="240" crop="true" density="2" order="5" />" width="120" height="120" alt="<perch:blog id="authorGivenName" type="text" label="Given name" order="1" /> <perch:blog id="authorFamilyName" type="text" label="Given name" order="2" />" />
</perch:if>
<perch:blog id="author_biog" type="textarea" suppress="true" label="Biography" textile="true" editor="markitup" order="4" />
<perch:blog id="author_twitter" type="text" suppress="true" label="Twitter account" />
<perch:blog id="author_facebook" type="text" suppress="true" label="Facebook Profile URL" />

blog/post.php

<?php 
    include($_SERVER['DOCUMENT_ROOT'].'/dev/pta/perch/runtime.php'); 
    perch_layout('global.blog-header');
?>

<hr class="hr-spacer-inv space35">
<div class="container">
    <div class="row">

        <div class="col-md-8">
            <!-- Content
            ================================================== -->
            <?php perch_blog_post(perch_get('s')); ?>





            <!-- Comments
            ================================================== -->
            <?php perch_blog_post_comments(perch_get('s')); ?>
            <?php perch_blog_post_comment_form(perch_get('s')); ?>
        </div>  

        <!-- Blog Sidebar
        ================================================== -->
        <aside id="blog-sidebar">
            <div class="col-md-3 col-md-offset-1">
                <div class="article-details">

                    <?php perch_blog_author_for_post(perch_get('s')); ?>

                    <?php perch_blog_post_categories(perch_get('s')); ?>

                    <?php perch_blog_post_tags(perch_get('s')); ?>


                </div>

                <!-- Categories
                ================================================== -->
                <div class="sidebar-section first">
                    <div class="section-header">
                        <h2>Categories</h2>
                    </div>
                    <?php perch_blog_categories(); ?>
                </div>

                <!-- Recent Articles
                ================================================== -->
                <div class="sidebar-section">
                    <div class="section-header">
                        <h2>Recent Articles</h2>
                    </div>
                    <ul>
                        <li>
                            <h3><a href="/news--events/father-and-son-night/">Father and Son Night</a></h3>
                            <p> Eisenhower Elementary PTA is inviting all Father's and Son's to enjoy a fun night out together. Glo Mini Golf, a family friendly...</p>
                        </li>
                    </ul>
                </div>

                <!-- Calendar
                ================================================== -->
                <div class="sidebar-section">
                    <div class="section-header">
                        <h2>View by Date</h2>
                    </div>
                    <?php perch_blog_date_archive_years(); ?>
                    <?php perch_blog_date_archive_months(); ?>

                </div>

                <!-- Tag Cloud
                ================================================== -->
                <div class="sidebar-section">
                    <div class="section-header">
                        <h2>View by Date</h2>
                    </div>
                    <?php perch_blog_tags(); ?>

                </div>

            </div>
        </aside>    


    </div>
</div>

Perch information

    Perch: 2.8.21
    Production mode: Production (100)
    Installed apps: content (2.8.21), assets (2.8.21), categories (2.8.21), perch_blog (5.0), perch_events (1.9.2)
    DB driver: PDO
    DB tables: perch2_blog_authors, perch2_blog_comments, perch2_blog_index, perch2_blog_posts, perch2_blog_posts_to_tags, perch2_blog_sections, perch2_blog_tags, perch2_blogs, perch2_categories, perch2_category_counts, perch2_category_sets, perch2_content_index, perch2_content_items, perch2_content_regions, perch2_events, perch2_events_categories, perch2_events_to_categories, perch2_navigation, perch2_navigation_pages, perch2_page_templates, perch2_pages, perch2_resource_log, perch2_resource_tags, perch2_resources, perch2_resources_to_tags, perch2_settings, perch2_user_passwords, perch2_user_privileges, perch2_user_role_privileges, perch2_user_roles, perch2_users
    Users: 1
    App runtimes:

    <?php
        $apps_list = array(
            'content', 
            'categories',
            'perch_blog',
        );

    Scheduled tasks for perch_events: update_category_counts (60 mins)
    Scheduled tasks for perch_blog: delete_spam_comments (1440 mins)
    Editor plug-ins: markitup, redactor
    H1: 26acadb404a866da6c8eea51e650f0db
    L1: 0b625ab4dc7d7d17c950e9d41528b1d0
    headerColour: #ffffff
    content_singlePageEdit: 1
    helpURL:
    siteURL: /
    hideBranding: 0
    content_collapseList: 1
    lang: en-gb
    update_2.8.21: done
    latest_version: 2.8.15
    on_sale_version: 2.8.21
    perch_blog_update: 5.0.1
    perch_events_update: 1.8
    headerScheme: light
    perch_events_detail_url: /events/event.php?s={eventSlug}
    perch_blog_site_name: Eisenhower PTA News
    perch_blog_post_url: /dev/pta/blog/post.php?s={postSlug}
    perch_blog_slug_format: %Y-%m-%d-{postTitle}
    perch_blog_akismet_key:
    perch_blog_max_spam_days: 0
    dashboard: 0
    hide_pwd_reset: 0
    content_hideNonEditableRegions: 0
    content_frontend_edit: 0
    perch_blog_comment_notify: 0
    PERCH_DEVELOPMENT: 10
    PERCH_STAGING: 50
    PERCH_PRODUCTION: 100
    PERCH_DB_USERNAME: northify_perch
    PERCH_DB_SERVER: localhost
    PERCH_DB_DATABASE: northify_perch-pta
    PERCH_DB_PREFIX: perch2_
    PERCH_TZ: UTC
    PERCH_EMAIL_FROM: shawn@northify.com
    PERCH_EMAIL_FROM_NAME: Shawn North
    PERCH_LOGINPATH: /dev/pta/perch
    PERCH_PATH: /home/northify/public_html/dev/pta/perch
    PERCH_CORE: /home/northify/public_html/dev/pta/perch/core
    PERCH_RESFILEPATH: /home/northify/public_html/dev/pta/perch/resources
    PERCH_RESPATH: /dev/pta/perch/resources
    PERCH_HTML5: 1
    PERCH_RUNWAY:
    PERCH_ERROR_MODE: DIE
    PERCH_DATE_LONG: %d %B %Y
    PERCH_DATE_SHORT: %d %b %Y
    PERCH_TIME_SHORT: %H:%M
    PERCH_TIME_LONG: %H:%M:%S
    PERCH_RUNWAY_ROUTED:
    PERCH_STRONG_PASSWORDS:
    PERCH_DEBUG:
    PERCH_PREVIEW_ARG: preview
    PERCH_TEMPLATE_PATH: /home/northify/public_html/dev/pta/perch/templates
    PERCH_DEFAULT_DOC: index.php
    PERCH_DEFAULT_EXT: .php
    PERCH_PRODUCTION_MODE: 100
    PERCH_RWD:
    PERCH_HTML_ENTITIES:
    PERCH_SSL:
    PERCH_STRIPSLASHES:
    PERCH_PROGRESSIVE_FLUSH: 1
    PERCH_AUTH_PLUGIN:
    PERCH_DB_CHARSET: utf8
    PERCH_DB_PORT:
    PERCH_DB_SOCKET:
    PERCH_SESSION_TIMEOUT_MINS: 20

Hosting settings

    PHP: 5.4.45
    Zend: 2.4.0
    OS: Linux
    SAPI: cgi-fcgi
    Safe mode: not detected
    MySQL client: 5.5.42-37.1
    MySQL server: 5.5.42-37.1
    Extensions: Core, date, ereg, libxml, openssl, pcre, sqlite3, zlib, bcmath, bz2, calendar, ctype, curl, dom, hash, fileinfo, filter, ftp, gd, gettext, gmp, SPL, iconv, session, intl, json, mbstring, mcrypt, mssql, mysql, mysqli, odbc, standard, PDO, pdo_mysql, pdo_sqlite, Phar, posix, pspell, Reflection, imap, SimpleXML, soap, sockets, exif, tidy, tokenizer, wddx, xml, xmlreader, xmlrpc, xmlwriter, xsl, zip, cgi-fcgi, imagick, SourceGuardian, mhash, ionCube Loader, Zend Guard Loader
    GD: Yes
    ImageMagick: Yes
    PHP max upload size: 64M
    PHP max form post size: 64M
    PHP memory limit: 256M
    Total max uploadable file size: 64M
    Resource folder writeable: Yes
    Session timeout: 24 minutes
    Native JSON: Yes
    Filter functions: Yes
    Transliteration functions: Yes
    DOCUMENT_ROOT: /home/northify/public_html
    GATEWAY_INTERFACE: CGI/1.1
    HTTP_ACCEPT: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
    HTTP_ACCEPT_ENCODING: gzip, deflate
    HTTP_ACCEPT_LANGUAGE: en-US,en;q=0.5
    HTTP_CONNECTION: close
    HTTP_COOKIE: cmsa=1; _ga=GA1.2.10942606.1452610075; cmssb=0; PHPSESSID=94369e73a9f7e600f43f204687c7df65
    HTTP_HOST: northify.com
    HTTP_REFERER: https://northify.com/dev/pta/perch/core/settings/diagnostics/
    HTTP_USER_AGENT: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:43.0) Gecko/20100101 Firefox/43.0
    HTTP_VIA: 1.1 websensewcg.hke.local 0A7802AD
    HTTP_X_HTTP_PROTO: HTTP/1.1
    HTTP_X_LOG_7914: 209.203.79.110
    HTTP_X_REAL_IP: 209.203.79.110
    PATH: /bin:/usr/bin
    PHPRC: /opt/php54/lib
    QUERY_STRING: extended
    REDIRECT_STATUS: 200
    REMOTE_ADDR: 209.203.79.110
    REMOTE_PORT: 30958
    REQUEST_METHOD: GET
    REQUEST_URI: /dev/pta/perch/core/settings/diagnostics/?extended
    SCRIPT_FILENAME: /home/northify/public_html/dev/pta/perch/core/settings/diagnostics/index.php
    SCRIPT_NAME: /dev/pta/perch/core/settings/diagnostics/index.php
    SERVER_ADDR: 192.185.195.65
    SERVER_ADMIN: webmaster@northify.com
    SERVER_NAME: northify.com
    SERVER_PORT: 80
    SERVER_PROTOCOL: HTTP/1.1
    SERVER_SIGNATURE: <address>Apache Server at northify.com Port 80</address>
    SERVER_SOFTWARE: Apache
    UNIQUE_ID: VpZp1MC5s4oAAGQaW2UAAAA6
    PHP_SELF: /dev/pta/perch/core/settings/diagnostics/index.php
    REQUEST_TIME_FLOAT: 1452698068.12
    REQUEST_TIME: 1452698068
    argc: 1
Drew McLellan

Drew McLellan 2638 points
Perch Support

An author doesn't have a postDateTime field.

You can always see what fields are available by using <perch:showall /> in your template.

How can I get postDateTime in my sidebar?

In my post.php file <?php perch_blog_post(perch_get('s')); ?> references the post.html file where the postDateTime is.

How can I use postDateTime in another template?

I also tried using this is my post.php file with a test.html template and that also does not give me the postDateTime.

<?php perch_blog_post(perch_get('s'), array(
    'template'   => 'test.html',
)); ?>

test.html

<p><strong>Posted:</strong>
    <perch:blog id="postDateTime" type="text" order="1" /> 
</p> 

Thanks

Drew McLellan

Drew McLellan 2638 points
Perch Support

What I was looking for....


perch_blog_custom(array( 'filter'=>'postSlug', 'match'=>'eq', 'value'=>perch_get('s'), 'template'=>'post_date_time.html', ));