Forum
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.
You shouldn't need to load the author in - it should just be available, e.g.
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...
The tags are still empty but the categories output "2" (Just the number 2)
Otherwise, page and content and everything are working just fine.
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.
Can you show me your diagnostics report?
Is this OK or do you need the whole thing?
I've just upgraded to perch 2.8.7 but no change unfortunately.
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
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
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
And here is the current code in blog/index.php
Thanks again (especially as its Sunday)
... 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 withpost_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:
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.
I'm not sure what to do with your questions if you're not asking for support! I guess I'll address them anyway.
Have you added your navigation group to the footer?
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?
Can you show me your tags template?
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.