CMS Development

benji_thecroc
Colaborador(a) | Parceiro Ouro
Colaborador(a) | Parceiro Ouro

Get blog slug and name in recent posts loop

resolver

Hi

 

Is there a way to pull the slug, name and URL of the blog a post belongs to?

 

For example we have a landing page that will pull in the most recent articles from three seperate blogs and to discern where each post belongs I want to use the slug as a classname, the name as a link with the URL to the Blog.

 

I wasn't able to find anything in the documentation but I did only briefly look through.

 

Here's an example of my code so far -

 

          {% set rec_posts = blog_recent_posts('5788265122, 8759379468, 8759379470', 6) %}
          {% for rec_post in rec_posts %}
          <div class="col-lg-4 col-md-6 col-12 BLOG-SLUG">
            <div class="story-block">
              <div class="story-thumb">
                <a href="{{ rec_post.absolute_url }}">
                  <div class="thumb-height"></div>
                  <div class="thumb-img" style="background-image: url('{{ rec_post.featured_image }}')">
                    <img src="{{ rec_post.featured_image }}" alt="">
                  </div>
                </a>
              </div>
              <div class="story-text">
                <div class="author-icon">
                  <img src="{{ rec_post.blog_author.avatar }}" alt="">
                </div>
                <div class="author-name">
                  {{ rec_post.blog_post_author.display_name }}
                </div>
                <a href="{{ rec_post.absolute_url }}">
                  <h4>{{ rec_post.name }}</h4>
                </a>
                <p>{{ rec_post.post_summary }}</p>
                <p>
                  {{ rec_post.group.id }}
                </p>
                <a href="{{ rec_post.absolute_url }}" class="read-more">Read more <i class="fa fa-angle-right" aria-hidden="true"></i></a>
                <div class="blog-name">
                  <hr>
                  <a href="BLOG URL">BLOG NAME</a>
                </div>
              </div>
            </div>
          </div>
          {% endfor %}
0 Avaliação positiva
1 Solução aceita
benji_thecroc
Solução
Colaborador(a) | Parceiro Ouro
Colaborador(a) | Parceiro Ouro

Get blog slug and name in recent posts loop

resolver

Here's my solution -

 

          {% set blog_one_posts = blog_recent_posts('8759379468', limit=6) %}
          {% set blog_two_posts = blog_recent_posts('8759379470', limit=6) %}
          {% set blog_three_posts = blog_recent_posts('5787859864', limit=6) %}
          {% set rec_posts = (blog_one_posts + blog_two_posts + blog_three_posts) | sort(true, false, 'publish_date')  %}
          {% for rec_post in rec_posts %}
          {% if loop.revindex >= 6 %}
          <div class="col-lg-4 col-md-6 col-12 {{ rec_post.parent_blog.slug }}">
            <div class="story-block">
              <div class="story-thumb">
                <a href="{{ rec_post.absolute_url }}">
                  <div class="thumb-height"></div>
                  <div class="thumb-img" style="background-image: url('{{ rec_post.featured_image }}')">
                    <img src="{{ rec_post.featured_image }}" alt="">
                  </div>
                </a>
              </div>
              <div class="story-text">
                <div class="author-icon">
                  <img src="{{ rec_post.blog_author.avatar }}" alt="">
                </div>
                <div class="author-name">
                  {{ rec_post.blog_post_author.display_name }}
                </div>
                <a href="{{ rec_post.absolute_url }}">
                  <h4>{{ rec_post.name }}</h4>
                </a>
                <div class="summary">
                  {{ rec_post.post_summary }}
                </div>
                <a href="{{ rec_post.absolute_url }}" class="read-more">Read more <i class="fa fa-angle-right" aria-hidden="true"></i></a>
                <div class="blog-name">
                  <hr>

                  <a href="{{ rec_post.parent_blog.absolute_url }}">{{ rec_post.parent_blog.public_title }}</a>
                </div>
              </div>
            </div>
          </div>
          {% endif %}
          {% endfor %}

Exibir solução no post original

1 Resposta 1
benji_thecroc
Solução
Colaborador(a) | Parceiro Ouro
Colaborador(a) | Parceiro Ouro

Get blog slug and name in recent posts loop

resolver

Here's my solution -

 

          {% set blog_one_posts = blog_recent_posts('8759379468', limit=6) %}
          {% set blog_two_posts = blog_recent_posts('8759379470', limit=6) %}
          {% set blog_three_posts = blog_recent_posts('5787859864', limit=6) %}
          {% set rec_posts = (blog_one_posts + blog_two_posts + blog_three_posts) | sort(true, false, 'publish_date')  %}
          {% for rec_post in rec_posts %}
          {% if loop.revindex >= 6 %}
          <div class="col-lg-4 col-md-6 col-12 {{ rec_post.parent_blog.slug }}">
            <div class="story-block">
              <div class="story-thumb">
                <a href="{{ rec_post.absolute_url }}">
                  <div class="thumb-height"></div>
                  <div class="thumb-img" style="background-image: url('{{ rec_post.featured_image }}')">
                    <img src="{{ rec_post.featured_image }}" alt="">
                  </div>
                </a>
              </div>
              <div class="story-text">
                <div class="author-icon">
                  <img src="{{ rec_post.blog_author.avatar }}" alt="">
                </div>
                <div class="author-name">
                  {{ rec_post.blog_post_author.display_name }}
                </div>
                <a href="{{ rec_post.absolute_url }}">
                  <h4>{{ rec_post.name }}</h4>
                </a>
                <div class="summary">
                  {{ rec_post.post_summary }}
                </div>
                <a href="{{ rec_post.absolute_url }}" class="read-more">Read more <i class="fa fa-angle-right" aria-hidden="true"></i></a>
                <div class="blog-name">
                  <hr>

                  <a href="{{ rec_post.parent_blog.absolute_url }}">{{ rec_post.parent_blog.public_title }}</a>
                </div>
              </div>
            </div>
          </div>
          {% endif %}
          {% endfor %}