Other - 2020-08-25
HubSpotのブログで人気記事を表示する方法
全てのHubLのコード
{% set pop_posts = blog_popular_posts('default', 5) %}
<div class="popular">
<h2 class="popular-title">人気記事</h2>
{% for pop_post in pop_posts %}
<a href="{{pop_post.absolute_url}}" class="popular-articles">
{% if pop_post.post_list_summary_featured_image %}
<img src="{{ pop_post.post_list_summary_featured_image }}" class="popular-articles-image" alt="{{ pop_post.featured_image_alt_text | escape }}">
{% endif %}
<h3 class="popular-articles-title">{{ pop_post.name }}</h3>
<p class="post-header-title-data">記事公開日: {{ pop_post.publish_date_local_time.strftime('%Y.%m.%d') }}</p>
<p>{{ pop_post.post_body|truncate(31, True, '…' ) }}</p>
</a>
{% endfor %}
{% if pop_post.topic_list %}
<p id="popular-articles-topic"> トピック:
{% for topic in pop_post.topic_list %}
<a class="popular-articles-topic-link" href="{{ blog_tag_url(group.id, topic.slug) }}">{{ topic.name }}</a>
{% endfor %}
</p>
{% endif %}
</div>
個別のHubLのコード
人気記事の取得方法
{% set pop_posts = blog_popular_posts('default', 5) %}
{% for pop_post in pop_posts %}
//中身
{% endfor %}
タイトルの取得方法
<h3 class="popular-articles-title">{{ pop_post.name }}</h3>
記事公開日の取得方法
<p class="post-header-title-data">記事公開日: {{ pop_post.publish_date_local_time.strftime('%Y.%m.%d') }}</p>
記事URLの取得方法
<a href="{{pop_post.absolute_url}}" class="popular-articles"></a>
本文の取得方法
<p>{{ pop_post.post_body|truncate(31, True, '…' ) }}</p>
サムネイルの取得方法
{% if pop_post.post_list_summary_featured_image %}
<img src="{{ pop_post.post_list_summary_featured_image }}" class="popular-articles-image" alt="{{ pop_post.featured_image_alt_text | escape }}">
{% endif %}
トピック(タグ)の取得方法
{% if pop_post.topic_list %}
<p id="popular-articles-topic"> トピック:
{% for topic in pop_post.topic_list %}
<a class="popular-articles-topic-link" href="{{ blog_tag_url(group.id, topic.slug) }}">{{ topic.name }}</a>
{% endfor %}
</p>
{% endif %}
Related Posts
Related Posts