CMS Development

ahein624
Membre

Pulling a Blog Post Meta Description

Résolue

I want to pull a blog post meta descritption for a post listing module I am designing for our homepage. Does anyone know of a way to do this? Or is there a way to  truncate the body content to a certain character count?

 

Here is the module I am building:

 

{% set posts = blog_recent_posts ('default', 3) %}
{% for post in posts %}
<div class="background_focus_image span4 widget-span" style="background:linear-gradient(0deg, rgba(000,000,000,0.5), rgba(000,000,000,0.5)) repeat ,url({{ post.post_list_summary_featured_image }}) no-repeat center bottom; background-size: cover;">
    <div class="homepage_title_backer">
        <h2><a href="{{ post.absolute_url }}">{{ post.name }}</a></h2>
    </div>
    <div class="homepage_desc">
        <p>{{ meta description or truncated contnet would go here }}</p>
    </div>
    <div class="homepage_CTA">
        <a href="{{ post.absolute_url }}" class="hs-button">Read More</a>
    </div>
</div>
{% endfor %}

 

0 Votes
1 Solution acceptée
Jlamb1
Solution
Contributeur

Pulling a Blog Post Meta Description

Résolue

{{ content.meta_description }}
is the tag to pull the meta description of a page - though if this is on the listing page it might just pull the listing page's description.
 
{{ content.post_body|truncate(25) }}
Will allow you to pull the post body and limit to a certain number of characters. 25 can be switched out to whatever limit you want (max of 255 characters).

 

{{ content.post_summary }} will print the blog post summary - this is what appears before the "read more" separator on your page.

Voir la solution dans l'envoi d'origine

3 Réponses
Jlamb1
Solution
Contributeur

Pulling a Blog Post Meta Description

Résolue

{{ content.meta_description }}
is the tag to pull the meta description of a page - though if this is on the listing page it might just pull the listing page's description.
 
{{ content.post_body|truncate(25) }}
Will allow you to pull the post body and limit to a certain number of characters. 25 can be switched out to whatever limit you want (max of 255 characters).

 

{{ content.post_summary }} will print the blog post summary - this is what appears before the "read more" separator on your page.

cliffypop
Membre

Pulling a Blog Post Meta Description

Résolue

I'd love to know the if/else statement I can use to amend my blog Listing Template that will print anything entered in the Meta Description field OR use a truncated version of the body content (if nothing is entered in the Meta Description field).

0 Votes
edjusten
HubSpot Employee
HubSpot Employee

Pulling a Blog Post Meta Description

Résolue

Hi @ahein624    Perhaps @Jsum can provide some guidance here? 

 

Thank you,

Ed Justen


Did my post help answer your query? Help the Community by marking it as a solution
0 Votes