CMS Development

Theodor
Participant | Elite Partner
Participant | Elite Partner

Popular blog posts not appearing on one blog

Hello,

 

I have this strange bug on one my client's blog.

Below the listing, I have a popular article block. It's the same custom module for both blogs, lets call them Blog A and Blog B

 

This is the loop which generates the popular listing :

{% set pop_posts = blog_popular_posts(module.blog_id, 2) %}

{% for pop_post in pop_posts %}

{{ pop_post.publish_date_localized }}
 <h3><a href="{{ pop_post.absolute_url }}">{{ pop_post.name }}</a></h3> .... The huble continues...

{% endfor %}

I pasted only the huble part whitout the html. As you can see the goal is to have only two articles showing (the "module.blog_id" is the huble text field which contains the blog id, I need it in order to use the same custom module on other blogs).

 

The thing is that it works for one blog : Blog A, but it doesn't for Blog B, which is strange because it's the exact bit of code for both.

 

I checked : 

- If the correct id is used for each blog

- The loop seems to work

- I clicked on as many as articles as possible to generate "popularity"

- The only way to get an article to show up on Blog B is to change the number of articles to show from 2 to 4, and I get only one article showing with this method on Blog B, but 4 on Blog A (obviously 🙂 ).

 

Hope you can help.

Thanks in advanced !

0 Upvotes
3 Replies 3
lscanlan
HubSpot Alumni
HubSpot Alumni

Popular blog posts not appearing on one blog

Hey @Theodor,

 

That behavior sounds a little off. Could you link me to the blog(s) / module? I can take a look at the code and see if maybe something needs to be taken a look at by and engineer.

 

Thanks,

Leland

Leland Scanlan

HubSpot Developer Support
0 Upvotes
Theodor
Participant | Elite Partner
Participant | Elite Partner

Popular blog posts not appearing on one blog

Hello Leland,

 

Thank you for your answer, here is the code generating the popular post : 

{% set pop_posts = blog_popular_posts(module.blog_id, 2) %}

<div class="pop--container">
  {% for pop_post in pop_posts %}
    <div class="pop--item">
      <div class="pop--content">
        <div class="pop-item-details">
          <div class="pop-item-topics">
            {% for topic in pop_post.topic_list %}
              <a class="topic-link" href="{{ blog_tag_url(group.id, topic.slug) }}">{{ topic.name }}</a>
            {% endfor %}
          </div>

          <div class="pop-publish-date">
            {{ pop_post.publish_date_localized }}
          </div>

          <div class="pop-item-title">
            <h3><a href="{{ pop_post.absolute_url }}">{{ pop_post.name }}</a></h3>
          </div>

          <div class="pop-item-summary">
            {% if pop_post.post_list_content %}
              <p>{{ pop_post.post_summary|striptags|truncate(130,true,' ...') }}</p>
            {% endif %}
          </div>

          <div class="pop-read-time">
            <div class="pop-item-read-more transparent-cta-style-blue">
              <a class="more-link" href="{{ pop_post.absolute_url }}">{{ module.read_more_translator }}</a>
            </div>

            <div class="pop-item-reading--time">
              <p>{{ pop_post.widgets.module_15530017180411446.body.article_reading_time }}</p>
            </div>
          </div>
        </div>
        <div class="pop-feat-img no-line-height">
          <img src="{{ pop_post.post_list_summary_featured_image }}" class="" alt="{{ pop_post.featured_image_alt_text | escape }}">
        </div>
      </div>
    </div>
  {% endfor %}
</div>

I'm also using some custom modules to retrieve hubl variables which are inserted directly in the article, ie :

<p>{{ pop_post.widgets.module_15530017180411446.body.article_reading_time }}</p>

Thanks,

Theodor

0 Upvotes
lscanlan
HubSpot Alumni
HubSpot Alumni

Popular blog posts not appearing on one blog

Hi Theodor,

 

Thanks for that. I looked through what you pasted and I'm not seeing any syntax errors. Assuming the blog ID is correct I'd expect that to work. Do both blogs live in the same HubSpot account? If the one that's not working actually lives in a different account, it wouldn't be accessible to the blog_popular_posts() function. But other than that, I'd expect this to work.

 

Could you link me to where the actual module lives? Or a live blog page? I'd be able to log in that way. Feel free to send me a direct message if you'd like.

 

 - Leland

Leland Scanlan

HubSpot Developer Support
0 Upvotes