CMS Development

victorwu
Participant

how can i create a popular-posts in list include different blogs post.

i want to create a module it can run two or more different blogs posts in a list. 

but this code below isn't work. does any one can help me?

螢幕快照 2019-07-29 上午11.22.26.png

4 Replies 4
lscanlan
HubSpot Alumni
HubSpot Alumni

how can i create a popular-posts in list include different blogs post.

Hi @victorwu,

 

Are those IDs for specific blog posts or for entire blogs? It sounds like you're trying to get the most popular posts from 2 separate blogs? That is possible, although the blog_popular_posts() function doesn't support it. You'll need to use the function twice and then add the lists together. So for example:

 

{% set popular_posts_one = blog_popular_posts(11653891338, 3) %}
{% set popular_posts_two = blog_popular_posts(11612398887, 3) %}
{% set popular_posts_all = (popular_posts_one + popular_posts_two)|sort('false', 'false', 'publish_date') %}

This will give you a list named popular_posts_all whose posts include the 3 most popular posts from blog ID 11653891338 and the 3 most popular posts from blog ID 11612398887, sorted by publish date. You can then loop through them, including a conditional for the loop index. Something like this for example:

 

{% for popular_post in popular_posts_all %}
  {% if loop.index < 4 %}
    {# HTML for blog posts here #}
  {% endif %}
{% endfor %}

...will give you the 3 most recently published posts in your list.

 

Let me know if I've misunderstood your goal though.

 

Leland Scanlan

HubSpot Developer Support
0 Upvotes
victorwu
Participant

how can i create a popular-posts in list include different blogs post.

Hello Iscanlan

i'm try entire blogs popular posts on list. 

and also tried to your code, but it still no work. 

please check my code, Thank you.

螢幕快照 2019-08-07 下午1.32.21.png

0 Upvotes
lscanlan
HubSpot Alumni
HubSpot Alumni

how can i create a popular-posts in list include different blogs post.

Hi @victorwu,

 

Make sure you're using the correct variable name inside your loop. Since you're writing your for loop like this:

 

{% for popular_post in popular_posts_all %}

...you'll need to make sure that you're using the variable popular_post inside your loop. So for example, instead of:

 

<a href="{{ pop_post.absolute_url }}" class="hs-rss-title"><span>{{ pop_post.name }}</span></a>

...make sure you're using this:

 

<a href="{{ popular_post.absolute_url }}" class="hs-rss-title"><span>{{ popular_post.name }}</span></a>

Does that make sense? If you're still not seeing your blog posts, could you link me to where you're working? I'm happy to take a look.

 

Leland Scanlan

HubSpot Developer Support
0 Upvotes
victorwu
Participant

how can i create a popular-posts in list include different blogs post.

thank you. it work

0 Upvotes