Forum
How do I output each post's tags and categories in the post_in_list.html templat...
On the main blog list, alongside the post's title, link, an excerpt, the date it was posted and the author, I'd also like to output the categories it belongs to and any tags it's been given. A bit like this site: https://www.teehanlax.com/blog/
I've tried playing around with <perch:blog id="tagSlug" />
and <perch:blog id="tagTitle" />
but it doesn't work… Can't use php since the template files are html, so <?php perch_blog_tags(); ?>
and <?php perch_blog_categories(); ?>
are out.
Thanks for taking a look :)
Martin.
You can use the
each
optionThen in your template
Thanks Drew. How do I include my template in the array?
This doesn't work
By the way, I didn't get an email notification for your reply and can't find anything to turn them on…
You can set the options on
perch_blog_post_categories()
in the usual way:Email notifications are being worked on.
I've got this now:
I've got this in my post_in_list.html template:
and the category_only.html template looks like this:
The categories aren't appearing on the page. I'm doing something daft, aren't I…? Can you see what I'm doing? Sorry :\
Oh, you need to return it:
Thanks very much! It's working now (sort of…):
If I set the count to 1 it tells me it's 'page 1 of 1', rather than 'page 1 of 2' (there are 2 posts at the minute, while I'm building the blog). Adding 'pagination' => true, to the array doesn't do anything either, but I'm assuming that's because it thinks there's only one page. Here's what I'm doing:
Also, if there's more than one category returned for a given post, is there any way to pop a comma and a space after all but the last category using PHP magic? I could do it with CSS but it feels like something that should come from the back end.
Can you confirm you're on Blog 4.1?
Nope– just checked my RSS (haha– I'm one of the 'special' few who still uses it!) and noticed yesterday's releases! I'll get everything updated and see if it fixes things. Here's my current setup:
Perch: 2.4.9 Production mode: Development (10) Installed apps: content (2.4.9), perch_forms (1.7), perch_blog (4.0.3), perch_backup (1.2)
Ok, great. That pagination issue should be fixed in 4.1.
Works a treat! Thanks :)
Do you know how I might tackle the space and comma issue with the back-end? I'm using perch:every to output a space and comma after every item, but is there a way to override the last item with no content? The only CSS-style attribute that seems works is
nth-child
, so I can't put alast-child
in there…Using
perch:every
doesn't make sense if withcount="1"
- its unnecessary. You should be able to just do this:Thanks– works nicely! Didn't realise there was a perch_item_last :)
Final part of this puzzle: do you know how how I'd get the
'each' => function($item)
code into my archive.php page? The code's a bit more complex there…Worst case scenario, I could just use a different template that doesn't have the category in it, but it would be cool if it mirrored my blog/index.php page.
Thanks again for all your help.
(The markdown support in the new forum is great, by the way!)
Are you using the example archive page, or something custom? You should just be able to pop it into the options before the
perch_blog_custom()
call.Makes sense– sorry! I've done it now and it's working nicely. Thanks again for all of your help :)