Forum

Thread tagged as: Question, Addons, Blog

Differentiate blog post types in post_in_list.html

I've got a couple of different blog post types and would like to give each an icon on the blog index page, depending on what the content is. For example, I'd like a post from a video post type to have a class of 'video' on the <li> on the index page. I'm trying this but it doesn't work:

My video post template in /templates/blog/posts/ has a hidden field with a default value:

<perch:blog id="video_marker" type="hidden" suppress="true" default="video" />

I was hoping this would automatically populate the database entry for each video post type with a value of 'video' so that I could then pull the class back out in the post_in_list.html template with the 'video_marker' ID like this:

<li class="hentry <perch:blog id="video_marker" />" >

I'd then be able to have a film camera icon that sits next to each video-centric post (<li class="video">), generated with my CSS.

Do you know if there's a way to achieve this?

Thanks :)

Martin Underhill

Martin Underhill 5 points

  • 7 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

The postTemplate id should list the template the post is using.

Sounds a lot less convoluted :) How can I output that to the HTML?

Drew McLellan

Drew McLellan 2638 points
Perch Support

<perch:blog id="postTemplate" />

Haha I thought it would be a lot more complicated than that!

It's outputting this:

posts/video_post.html

Is there any way to take the filename only, without the directory or file extension?

Actually, I've just used this to target the post type:

[class*="video_post"] {
  background-color: green;
}

So at least I can do what i want to do :) If I can still strip the id back to only video_post that would make me happy though– my HTML feels a bit weird now…

Drew McLellan

Drew McLellan 2638 points
Perch Support

You can use the replace attribute to replace the bits you don't want with nothing.

Mind=blown! 'Replace' is my new favourite thing! This is working just the way I wanted it to now:

<perch:blog id="postTemplate" replace="posts/|,.html|" />

Thanks Drew :)