CMS Development

SEsposito4
Participant

Blog Listing Page Featured Images

SOLVE

Would there be a way to edit the blog listing page source code to add a conditional to see if the URL is a "tag" or a "author" and remove the featured images from those listing pages?

 

"<div class="post-item">
{% if not simple_list_page %}
{% if content.post_list_summary_featured_image %}
<div class="hs-featured-image-wrapper">
<a href="{{content.absolute_url}}" title="" class="hs-featured-image-link">
<img src="{{ content.post_list_summary_featured_image }}" class="hs-featured-image">
</a>
</div>
{% endif %}"

 

I am not a developer but feel comfortable making small edits in the code if this would be a fairly easy function. 

0 Upvotes
1 Accepted solution
evaldas
Solution
Key Advisor | Platinum Partner
Key Advisor | Platinum Partner

Blog Listing Page Featured Images

SOLVE

Based on the code you shared, to hide the featured image in tag or author listing, you can wrap the conditional featured image code:

 

{% if content.post_list_summary_featured_image %}
<div class="hs-featured-image-wrapper">
<a href="{{content.absolute_url}}" title="" class="hs-featured-image-link">
<img src="{{ content.post_list_summary_featured_image }}" class="hs-featured-image">
</a>
</div>
{% endif %}

 

with the combined tag/author if statement, so it would look like this:

 

 

{% if !tag && !blog_author %}
{% if content.post_list_summary_featured_image %}
  <div class="hs-featured-image-wrapper">
  <a href="{{content.absolute_url}}" title="" class="hs-featured-image-link">
    <img src="{{ content.post_list_summary_featured_image }}" class="hs-featured-image">
  </a>
  </div>
{% endif %}
{% else %}
 {# if you need to replace the image with something else, do it here #}
{% endif %}

 

 

The text in between {# #} is a comment in HubL, so you can replace that with something else in place of the featured image or just leave it like that to not add anything else. 

 

So essentially replace the first part from your code with the wrapped version.


✔️ Did this post help answer your query? Help the community by marking it as a solution.

View solution in original post

3 Replies 3
evaldas
Key Advisor | Platinum Partner
Key Advisor | Platinum Partner

Blog Listing Page Featured Images

SOLVE

Hi @SEsposito4,

 

Yes, there are tag and author conditionals for the blog listing page.

 

If user is viewing the Tag blog listing page:

 

{% if tag %} your code here... {% endif %}

 

If user is viewing the Author blog listing page:

 

{% if blog_author %} your code here... {% endif %}

 

You can combine these two and create a rule that will show a featured image if the listing page is neither Author nor Tag. Below is an example that would show the featured image if blog listing is not tag and not author, but if it is (else),  it would show a custom featured image. 

 

{% if !tag && !blog_author %}
<img src="{{ content.post_list_summary_featured_image }}" class="hs-featured-image">
{% else %}
<img src="custom-featured-image.png" class="hs-featured-image">
{% endif %}

 

You code sample currently depends on an image being there for users to be able to click into the post, so you will need to customize it to your needs. 

 

Hope this helps!


✔️ Did this post help answer your query? Help the community by marking it as a solution.

SEsposito4
Participant

Blog Listing Page Featured Images

SOLVE

Hi @evaldas, this is very hepful I just have one more question, where would be the right place to insert this into the code?

0 Upvotes
evaldas
Solution
Key Advisor | Platinum Partner
Key Advisor | Platinum Partner

Blog Listing Page Featured Images

SOLVE

Based on the code you shared, to hide the featured image in tag or author listing, you can wrap the conditional featured image code:

 

{% if content.post_list_summary_featured_image %}
<div class="hs-featured-image-wrapper">
<a href="{{content.absolute_url}}" title="" class="hs-featured-image-link">
<img src="{{ content.post_list_summary_featured_image }}" class="hs-featured-image">
</a>
</div>
{% endif %}

 

with the combined tag/author if statement, so it would look like this:

 

 

{% if !tag && !blog_author %}
{% if content.post_list_summary_featured_image %}
  <div class="hs-featured-image-wrapper">
  <a href="{{content.absolute_url}}" title="" class="hs-featured-image-link">
    <img src="{{ content.post_list_summary_featured_image }}" class="hs-featured-image">
  </a>
  </div>
{% endif %}
{% else %}
 {# if you need to replace the image with something else, do it here #}
{% endif %}

 

 

The text in between {# #} is a comment in HubL, so you can replace that with something else in place of the featured image or just leave it like that to not add anything else. 

 

So essentially replace the first part from your code with the wrapped version.


✔️ Did this post help answer your query? Help the community by marking it as a solution.