CMS Development

jc9
Member

Change Blog Post layout based on Tag?

Let's say you have three different types of blog content:

  1. Text,
  2. Audio (like a podcast)
  3. Video (like a webinar)

Important: You want all of them to be on the same blog so they will appear in the same feed (and can be paginated), are searchable together, can share the same tags, and so on.

 

Now let's say you want a slightly different page layout for each content type. For example, you may want to embed the audio or video in those types of posts. Maybe you want a slightly different header, or different sidebar content.

 

How would you do this? Is there a way to have a different layout based on a tag or some other post metadata?

0 Upvotes
3 Replies 3
albertsg
Guide

Change Blog Post layout based on Tag?

Hi @jc9 ,

 

From my experience, what you could do is using a custom module to select the type of article template you want for your post.

Basically, you add a module in your main article template with X different options and inside the main template simply add an IF statement to load one or another partial template according to the value of this module.

 

By doing this you don't have to worry about dealing with tags and it's quite simple and intuitive for content creators. 



Did my answer help you? Mark it as a solution


Book time with me

You can also connect with me on LinkedIn



Anton
Recognized Expert | Diamond Partner
Recognized Expert | Diamond Partner

Change Blog Post layout based on Tag?

Hi @jc9,

 

yes - it's possible.

you can do something like

{% if is_listing_view %}

{% if topic == 'TOPIC 1 goes here'%}
{# Listingview for Topic 1 #}
...
{ elif topic ==' TOPIC 2 goes here'}
{# Listingview for Topic 2 #}
...

{% endif%}

{% endif %}

 

hope this helps

 

best, 

Anton

Anton Bujanowski Signature
psdtohubspot
Key Advisor

Change Blog Post layout based on Tag?

Hi @jc9 

Yes, it's possible.

I did this type of blog for many Clients.

 

Must use Custom Module with post by filter, pagination you must use jQuery.

 

Thankyou!

Ajit