La fonction de suggestion automatique permet d'affiner rapidement votre recherche en suggérant des correspondances possibles au fur et à mesure de la frappe.
sept. 9, 20194:26 PM - modifié sept. 10, 201910:04 AM
Participant
How to sort blog posts by a custom field
We ran into this issue where we wanted to sort items from a blog based on the contents of a custom field/module we added to that post type.
We noticed there are no solutions for this yet and discovered one that utilizes some undocumented features of Hubl. We're sharing it here for anyone else that might find it useful:
{# Detail Template -- Sorting Field #}
{% text 'sorting' label='Sorting Order #', no_wrapper=True, overrideable=True, export_to_template_context=True %}
{# Listing Template -- Sorting Logic #}
{% set post_list = blog_recent_posts('xxx', 999) %}
{% set post_list_sortable = [] %}
{% for post in post_list %}
{# Assign the index as a fallback, un-ordered items appear below explicitly ordered ones #}
{% set sort = post.widgets.sorting.body.value + 'x' + loop.index %}
{% set tmp = post_list_sortable.append({ 'sorting': sort, 'record': post}) %}
{% endfor %}
{# Templating Output #}
{% for post in post_list_sortable|sort(false, false, 'sorting') %}
{% set post = post.record %}
<h2>{{post.title}}</h2>
{% endfor %}
!important Set export_to_template_context=True. Then check your listing-page for content.widgets.blog_post_sorting.body.value.
Conclusion: This quick solution does not work with the blog pagination. Because it does not sort the HubSpot contents object. To work well, we have to avoid the pagination by increasing the amount of displayed blog articles in the blog settings. If your blog has a lot of articles, it is strongly recommended to use own filters or the existing tag filter and the default sorting by HubSpot.