Hola! ¡Tenemos nuestra Comunidad en Español!

I would like to get the image and the tags for latest post

Regular Visitor

I'm facing an issue I wanna get the tags and the image for the latest post;

 

Screenshot 2019-06-24_10-15-08-649.png

 

this is the code that I'm using from the documentation

Reply
0 Upvotes
2 Replies
Highlighted
Esteemed Advisor

Hi @amine1010 ,

 

You are settings a variable for your feed:

 

{% set tag_posts = blog_recent_tag_posts('default', 'Enterprise', 1) %} 

and you are looping through that variable:

 

 

{% for tag_post in tag_posts %}

{% endfor %}

so for each post that you loop through, you have access to that posts tokens:

 

 

{% for tag_post in tag_posts %}

    {{ tag_post.absolute_url }}
    {{ tag_post.name }}

{% endfor %}

 

You can wrap these tokens in html:

 

{% for tag_post in tag_posts %}

    <a href="{{ tag_post.absolute_url }}">
        <h2>{{ tag_post.name }}</h2>
    </a>

{% endfor %}

These tokens are the same whether you are working with the "contents" loop in a blog listing template, or using a custom posts function anywhere. You can find reference to these tokens in the HubL supported variables docs, under blog variables.

 

 

Because the custom post functions are looped through the same way you would loop through the "contents" variable in a listing template, you can also use the Blog content markup docs as reference. Here is a snippet for the featured image from that page, but I changed the item name in the loop to match yours so you can copy and paste it into your code:

 

   {% if tag_post.post_list_summary_featured_image %}
<div> <a href="{{tag_post.absolute_url}}"> <img src="{{ tag_post.post_list_summary_featured_image }}" alt="{{ tag_post.featured_image_alt_text }}"> </a> </div>
{% endif %}

 

Let me know if that helps.

 

- Jonathan Sumner
Regular Visitor

Thanks man, I've figured out how to solve that issue 

thank again @Jsum