Forum

Thread tagged as: Question, Problem, Blog

Extra blog info in post_in_list.html

I'm trying to display the tags, categories and author on the post_in_list.html template. The below code does not output anything. No errors, just no data. The post itself is output just fine, as is the rest of the page.

I've read a handful of posts that deal with this. I must be doing something wrong, Can anyone help?

in /blog/index.php

<?php perch_blog_custom(array(
                        'template' => 'post_in_list.html',
                        'each' => function($item) {
                            $item['categories'] = perch_blog_post_categories($item['postID'], array(
                                'template'=>'category_only.html'
                                ), true);
                            $item['tags'] = perch_blog_post_tags($item['postID'], array(
                                'template'=>'tag_only.html'
                                ), true);
                            $item['author'] = perch_blog_author(perch_get('author'), array(
                                    'template' => 'author_name.html',
                                ), true);
                            return $item;
                        },
                        'count' => 10
                        ));
                    ?>

in post_in_list.html

<div class="meta-author-category pull-left">
                <span class="post-author">by <a href="#">
                    <perch:blog id="author" encode="false" />
                </a></span>
                <span class="post-category">In: <perch:blog id="categories" encode="false" /></span>
            </div>
            <div class="meta-tag-comment pull-right">
                <span class="post-tags"><i class="fa fa-tag"></i> <perch:blog id="tags" encode="false" /></span>
                <span class="post-comment"><i class="fa fa-comments"></i> <a href="<perch:blog id="postURL" />"><perch:blog id="postCommentCount"/> Comments</a></span>
            </div>

category template

<a href="/blog/category/<perch:blog id="categorySlug" />"><perch:blog id="categoryTitle" /></a>

I'm sure I'm going to kick myself!

New to Perch but loving it so far.

Caleb Evans

Caleb Evans 1 points

  • 6 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

You shouldn't need to load the author in - it should just be available, e.g.

<perch:blog id="authorGivenName" />

Otherwise it looks ok - does it work without the each function? I'd not expect anything in the each to cause a problem.

Thanks for the reply.

Author now working as you have indicated. Brilliant.

If I remove the each function...

<?php perch_blog_custom(array(
                        'template' => 'post_in_list.html',
                        /*'each' => function($item) {
                            $item['categories'] = perch_blog_post_categories($item['postID'], array(
                                'template'=>'category_only.html'
                                ), true);
                            $item['tags'] = perch_blog_post_tags($item['postID'], array(
                                'template'=>'tag_only.html'
                                ), true);
                            return $item;
                        },*/
                        'count' => 10
                        ));
                    ?>

The tags are still empty but the categories output "2" (Just the number 2)

Otherwise, page and content and everything are working just fine.

Drew McLellan

Drew McLellan 2638 points
Perch Support

And if you add it back in nothing outputs at all?

That's correct.

There is only one test blog article, one category and two tags. The categories and tags show up in my side bar.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Can you show me your diagnostics report?

Perch is out of date. You are running Perch 2.8.6 and the latest is 2.8.7.
PHP 5.6.7 is up to date
MySQL 5.5.42 is up to date
Image processing available


Perch: 2.8.6, PHP: 5.6.7, MySQL: mysqlnd 5.0.11-dev - 20120503 - $Id: 3c688b6bbc30d36af3ac34fdd4b7b5b787fe5555 $, with PDO
Server OS: Darwin, apache2handler
Installed apps: content (2.8.6), assets (2.8.6), categories (2.8.6), perch_blog (4.6), perch_forms (1.8.3)
App runtimes: <?php $apps_list = array( 'content', 'categories', 'perch_forms', 'perch_blog' );
PERCH_LOGINPATH: /perch
PERCH_PATH: /Users/caleb/Documents/MAMP sites/Spark Ed/httpdocs/perch
PERCH_CORE: /Users/caleb/Documents/MAMP sites/Spark Ed/httpdocs/perch/core
PERCH_RESFILEPATH: /Users/caleb/Documents/MAMP sites/Spark Ed/httpdocs/perch/resources
Image manipulation: GD
PHP limits: Max upload 32M, Max POST 32M, Memory: 128M, Total max file upload: 32M
Resource folder writeable: Yes
HTTP_HOST: localhost:8888
DOCUMENT_ROOT: /Users/caleb/Documents/MAMP sites/Spark Ed/httpdocs
REQUEST_URI: /perch/core/settings/diagnostics/
SCRIPT_NAME: /perch/core/settings/diagnostics/index.php

Is this OK or do you need the whole thing?

I've just upgraded to perch 2.8.7 but no change unfortunately.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Clutching at straws, but could you try changing the array keys you're using to be something that can't clash with existing IDs?

Right. I tried changing the keys but that made no difference. I then thought I would run through everything and see if I could spot a problem. One thing I found can be seen in the this screen shot

screenshot

https://www.dropbox.com/s/s9tqvjpfec92pit/Screen%20Shot%202015-06-07%20at%2010.46.40.png?dl=0&raw=1 (I hope the image is viewable)

As you will (hopefully) see that the tags are duplicated with no label and the category is showing up as a text box with what I assume is the unique ID for the category.

This must mean I have made a mistake in my template somewhere. I've looked in post.html and that looks OK to me but presumably that is where I've caused the problem.

Thanks for your continued support.

post.html

<article class="entry-post">
    <header class="entry-header">
        <h2 class="entry-title">
            <a href="<perch:blog id="postURL" type="hidden" />"><perch:blog id="postTitle" type="text" label="Title" required="true" size="xl autowidth" order="1" /></a>
        </h2>
        <div class="meta-line clearfix">
            <div class="meta-author-category pull-left">
                <span class="post-author">by <a href="#"><perch:blog id="authorGivenName" type="hidden" /> <perch:blog id="authorFamilyName" type="hidden" /></a></span>
                <span class="post-category">In: 
                    <perch:categories id="categories" set="blog" label="Categories" display-as="checkboxes">
                    <a href="/blog/<perch:category id="catSlug" type="slug" />" class="p-category">
                    <perch:category id="catTitle" type="text" />
                </a>
            </perch:categories>
        </span>
    </div>
    <div class="meta-tag-comment pull-right">
        <span class="post-tags"><i class="fa fa-tag"></i> <perch:blog id="postTags" type="text" suppress="true" /></span>
        <span class="post-comment"><i class="fa fa-comments"></i> <a href="#COMMENTS"><perch:blog id="postCommentCount" suppress="true"/> Comments</a></span>
    </div>
</div>
</header>
<div class="entry-content clearfix">
    <figure class="featured-image">
        <div class="post-date-info clearfix"><span class="post-month"><perch:blog id="postDateTime" type="date" time="true" format="%B" /> </span><span class="post-date"><perch:blog id="postDateTime" type="date" time="true" format="%d" /> </span><span class="post-year"><perch:blog id="postDateTime" type="date" time="true" format="%Y" /> </span></div>
        <perch:if exists="image">
        <div>
            <img class="img-responsive" src="<perch:blog id="image" type="image" width="850" height="350" crop="true" label="Image" order="4" />" alt="<perch:blog id="postTitle" />" />
        </div>
    </perch:if>
</figure>
<div class="excerpt">
   <perch:blog id="postDescHTML" type="textarea" label="Post" order="2" editor="markitup" markdown="true" size="xxl autowidth" required="true" />
</div>
</div>
</article>

<perch:blog id="excerpt" type="textarea" label="Excerpt" markdown="true" editor="markitup" order="3" suppress="true" size="s" />
<perch:blog id="image" type="image" width="340" height="300" crop="true" suppress="true" />
<perch:blog id="image" type="image" width="360" height="190" crop="true" suppress="true" />
<perch:blog id="image" type="image" width="140" height="74" crop="true" suppress="true" />
Drew McLellan

Drew McLellan 2638 points
Perch Support

For the values you're setting in your code, set the corresponding template tags as type="hidden".

That will stop them showing up in the edit form. It also looks like they have values set, which may cause an issue if you're trying to override those values.

Thanks, That has sorted the admin display issue. Still no categories or tags showing in post_in_list.html.

I'm sure I'm doing something daft.

Here's the entire current post_in_list.html

<article class="entry-post">
    <header class="entry-header">
        <h2 class="entry-title">
            <a href="<perch:blog id="postURL" />"><perch:blog id="postTitle" /></a>
        </h2>
        <div class="meta-line clearfix">
            <div class="meta-author-category pull-left">
                <span class="post-author">by <a href="#">
                    <perch:blog id="authorGivenName" />
                </a></span>
                <span class="post-category">In: <perch:blog id="listcats" encode="false" /></span>
            </div>
            <div class="meta-tag-comment pull-right">
                <span class="post-tags"><i class="fa fa-tag"></i> <perch:blog id="listtags" encode="false" /></span>
                <span class="post-comment"><i class="fa fa-comments"></i> <a href="<perch:blog id="postURL" />#COMMENTS"><perch:blog id="postCommentCount" /> Comments</a></span>
            </div>
        </div>
    </header>
    <div class="entry-content clearfix">
        <div class="row">
            <div class="col-sm-5">
                <figure class="featured-image">
                    <a href="blog-single.html">
                        <div class="post-date-info clearfix"><span class="post-month"><perch:blog id="postDateTime" type="date" time="true" format="%B" /> </span><span class="post-date"><perch:blog id="postDateTime" type="date" time="true" format="%d" /> </span><span class="post-year"><perch:blog id="postDateTime" type="date" time="true" format="%Y" /> </span></div>
                        <perch:if exists="image"><img src="<perch:blog id="image" type="image" class="img-responsive" height="300" width="340" crop="true" />" alt="<perch:blog id="postTitle" />" /></perch:if>
                    </a>
                </figure>
            </div>
            <div class="col-sm-7">
                <div class="excerpt">
                    <perch:blog id="excerpt" type="textarea" textile="true" />
                    <p class="read-more">
                        <a href="<perch:blog id="postURL" />" class="btn btn-primary">Read More <i class="fa fa-long-arrow-right"></i></a>
                    </p>
                </div>
            </div>
        </div>
    </div>
</article>
<hr />

And here is the current code in blog/index.php

<div class="blog medium-thumbnail margin-bottom-30px">
                    <?php perch_blog_custom(array(
                        'template' => 'post_in_list.html',
                        'each' => function($item) {
                            $item['listcats'] = perch_blog_post_categories($item['postID'], array(
                                'template'=>'category_only.html'
                                ), true);
                            $item['listtags'] = perch_blog_post_tags($item['postID'], array(
                                'template'=>'tag_only.html'
                                ), true);
                            return $item;
                        },
                        'count' => 10
                        ));
                    ?>
                </div>

Thanks again (especially as its Sunday)

Drew McLellan

Drew McLellan 2638 points
Perch Support

... I'm now wondering why you got those fields in your edit form. Those fields should be coming from post.html but you're working with post_in_list.html for this.

Pasting your code into my site, I don't get the categories or tags (because I don't have your templates), but I do get the listing without them.

It also occurs to me that you don't need the categories part at all. Just do this in your template:

<perch:categories id="categories" set="blog" label="Categories">
            <a href="archive.php?cat=<perch:category id="catSlug" type="slug" />" class="p-category">
                <perch:category id="catTitle" type="text" />
            </a>
</perch:categories>

Great. That's sorted the categories.

Is it possible to do something similar with the tags?

I've also noticed that a navigation group I've created does not show in the footer (I've not really looked into this yet so wont bother posting code) and in the admin area, when I view a submitted form, the details do not show up n the list view but they are there in the details view.

I'm not asking for support for these new issues as I have not yet attempted to solve the problems myself, I just wondered if there might be a reason for all these lists not displaying.

Thanks again.

I'm still loving Perch.

Drew McLellan

Drew McLellan 2638 points
Perch Support

I'm not sure what to do with your questions if you're not asking for support! I guess I'll address them anyway.

I've also noticed that a navigation group I've created does not show in the footer (I've not really looked into this yet so won't bother posting code)

Have you added your navigation group to the footer?

and in the admin area, when I view a submitted form, the details do not show up n the list view but they are there in the details view.

Are you talking about the Forms app here?

My apologies, I wasn't clear. I wondered if these issues may be related in some way to the tags now showing up as they all deal with displaying lists in one way or another (tenuous I know).

I didn't want to to waste your time with silly questions when I had not tried to fix these things my self.

In my attempt not to muddy the waters of this post with different problem, I have managed to do just that!

Is it possible to solve the issue of the tags no displaying in a similar way to how we solved the categories issue?

Drew McLellan

Drew McLellan 2638 points
Perch Support

Can you show me your tags template?

<a href="/blog/tags/<perch:blog id="tagSlug" />"><perch:blog id="tagTitle" /></a>, 
Drew McLellan

Drew McLellan 2638 points
Perch Support

I'm at a bit of a loss. Is you page online anywhere?

Arghhhh... I had a typo in my template name. A missing "s"! It's now working. #feelingabitstupid

Thanks for all your help. I'll start a new thread for anything else I can't fix.