Show One Featured Blog Post

Hello! I have this module from one of the themes I downloaded that I love but it’s showing a LIST of all the featured blog posts when I want to preview just one. I was wondering if someone can look over this code for me? I tried taking away the for loop where it says “for contents” but it still generated the same thing. Thank you!

<div class="blog-section">
 <div class="blog-post-wrapper cell-wrapper">
 <div class="blog-section">
 <div class="blog-post-wrapper cell-wrapper">
 <div class="section post-header">
 <h1>{{ content.name }}</h1>
 <div id="hubspot-author_data" class="hubspot-editable" data-hubspot-form-id="author_data" data-hubspot-name="Blog Author" >
 <span class="hs-author-label">Posted by</span>
 {% if content.blog_post_author %}
 <a class="author-link" href="{{ blog_author_url(group.id, content.blog_post_author.slug) }}">{{ content.blog_post_author.display_name }}</a> on {{ content.publish_date_localized }}
 {% if content.blog_post_author.avatar %} <div class="hs-author-avatar"> <img src="{{ content.blog_post_author.avatar }}" alt="{{ content.blog_post_author.display_name }}"> </div> {% endif %}
 {% if content.blog_post_author.has_social_profiles %}
 <div class="hs-author-social-section">
 <span class="hs-author-social-label">Find me on:</span>
 <div class="hs-author-social-links">
 {% if content.blog_post_author.facebook %}
 <a href="{{ content.blog_post_author.facebook }}" target="_blank" class="hs-author-social-link hs-social-facebook">Facebook </a>
 {% endif %}
 {% if content.blog_post_author.linkedin %}
 <a href="{{ content.blog_post_author.linkedin }}" target="_blank" class="hs-author-social-link hs-social-linkedin">LinkedIn</a>
 {% endif %}
 {% if content.blog_post_author.twitter %}
 <a href="{{ content.blog_post_author.twitter }}" target="_blank" class="hs-author-social-link hs-social-twitter">Twitter </a>
 {% endif %}
 {% if content.blog_post_author.google_plus %}
 <a href="{{ content.blog_post_author.google_plus }}?rel=author" target="_blank" class="hs-author-social-link hs-social-google-plus">Google+</a>
 {% endif %}
 </div>
 </div>
 {% endif %}
 {% endif %}
 </div>
 </div>
 {% blog_social_sharing "blog_social_sharing" overrideable=False, label='Blog Social Sharing' %}
 <div class="section post-body">
 {{ content.post_body }}
 </div>
 {% if content.topic_list %}
 <p id="hubspot-topic_data" > Topics:
 {% for topic in content.topic_list %}
 <a class="topic-link" href="{{ blog_tag_url(group.id, topic.slug) }}">{{ topic.name }}</a>{% if not loop.last %},{% endif %}
 {% endfor %}
 </p>
 {% endif %}
 </div>
 </div>
 <!-- Optional: Blog Author Bio Box -->
 {#<div class="about-author-sec row-fluid">
 <div class="span2">
 <img alt="{{ content.blog_post_author.display_name }}" src="{{ content.blog_post_author.avatar }}">
 </div>
 <div class="span10">
 <h3>Written by <a class="author-link" href="{{ blog_author_url(group.id, content.blog_post_author.slug) }}">{{ content.blog_post_author.display_name }}</a></h3>
 <p>{{ content.blog_post_author.bio }}</p>
 {% if content.blog_post_author.has_social_profiles %}
 <div class="hs-author-social-section">
 <div class="hs-author-social-links">
 {% if content.blog_post_author.facebook %}
 <a href="{{ content.blog_post_author.facebook }}" target="_blank" class="hs-author-social-link hs-social-facebook">Facebook</a>
 {% endif %}
 {% if content.blog_post_author.linkedin %}
 <a href="{{ content.blog_post_author.linkedin }}" target="_blank" class="hs-author-social-link hs-social-linkedin">LinkedIn</a>
 {% endif %}
 {% if content.blog_post_author.twitter %}
 <a href="{{ content.blog_post_author.twitter }}" target="_blank" class="hs-author-social-link hs-social-twitter">Twitter</a>
 {% endif %}
 {% if content.blog_post_author.google_plus %}
 <a href="{{ content.blog_post_author.google_plus }}?rel=author" target="_blank" class="hs-author-social-link hs-social-google-plus">Google+</a>
 {% endif %}
 </div>
 </div>
 {% endif %}
 </div>
 </div>#}
 </div>
</div>

Hi @unicorndev,

this seems a lot like the boilerplate/session-theme one. Also where should the featured post area be?

If you want only the first/latest “featured post” you have many possible solutions. One of them would be to create an if-statement like this

...
{% for content in contents %}
{% if loop.first %}
{# place your markup for the featured image here #}
{% endif %}
{% endfor %}
...

best,

Anton

This is exactly what I was looking for! Yeah, it is from the boiler plate code and I couldn’t figure out how to just show one featured post.

Is there any way I can trim the featured post into just one paragraph? I just want the first paragraph shown then off to the ‘read more’ section. Thank you so much :slightly_smiling_face:

Hi @unicorndev,

you can limit the displayed text-length by many different filters like truncate or truncatehtml. Also if I’m not completly off HubSpot will automatically cut the text, if you have the “read-more” seperator

<!--more-->

in your text some where

Also I recommend to add the striptags filter to the content so it will be rendered just as text.

Showing just the first paragraph can lead to different heights/lengts which I wouldn’t recommend. Instead go with a truncate limitation of characters :wink:

best,

Anton