CMS Development

Blake32
参加者

If statement based on subdomain

I'm trying to create a recent posts section using this code. This will display at the bottom of blog posts. I have 4 blogs in Hubspot on different subdomains. Is it possible to write an if statement that will print the recent posts based on which blog it's on? If that isn't possible, is there some other way of doing this without creating 4 separate blog post templates?

 

I was thinking something like:

{% if blogid='subdomain1' %}
{% set posts = blog_recent_posts('SUBDOMAIN1', 3) %}
{% for post in posts %}
    <h3><a href="{{ post.absolute_url }}">{{ post.name }}</a></h3>
    <img src="{{ post.featured_image }}" alt="{{ post.name }}">
{% endfor %}
{% elif blogid='subdomain2' %}
{% set posts = blog_recent_posts('SUBDOMAIN2', 3) %}
{% for post in posts %}
    <h3><a href="{{ post.absolute_url }}">{{ post.name }}</a></h3>
    <img src="{{ post.featured_image }}" alt="{{ post.name }}">
{% endfor %}

and so on...
0 いいね!
1件の返信
stefen
キーアドバイザー | Solutions Partner
キーアドバイザー | Solutions Partner

If statement based on subdomain

@Blake32 you should be able to get that working using the HubL variable "request.domain" in your if statement. For example:

{% if request.domain is string_containing "www" %}
you're viewing a page with a WWW subdomain!
{% endif %}

 

Stefen Phelps, Community Champion, Kelp Web Developer
0 いいね!