Posts Section
The Posts Section Block displays posts from the Blog entry type according to specified settings. The section's display behavior is controlled by the following settings:
settings.enable_blog
: Defined in the Settingssection.reverse_order
: A boolean value indicating whether the posts should be displayed in reverse order.section.show_specific_items
: A boolean value indicating whether specific posts should be displayed.section.specific_items
: An array of specific posts to display, ifsection.show_specific_items
istrue
.section.filter_by_category
: A boolean value indicating whether the posts should be filtered by category.section.post_category_filter
: The category to filter posts by, ifsection.filter_by_category
istrue
.section.sort_by
: A string value indicating how to sort the posts. Possible values are'title'
or'date'
.section.enable_pagination
: A boolean value indicating whether to display the posts with pagination.section.limit
: An integer value indicating the number of posts to display per page, ifsection.enable_pagination
istrue
.
Based on these settings, the code is executing the following operations:
If
section.show_specific_items
istrue
, the code initializes an empty arrayposts
and pushes specific posts into it.If
section.filter_by_category
istrue
, the code filters theposts
array to only include posts that belong to the specified category.If
section.sort_by
is'title'
, the code sorts theposts
array either ascending or descending based onsection.reverse_order
. Ifsection.show_specific_items
isfalse
, the code sorts the posts using theorderBy
function, otherwise, the code sorts the posts using thesortBy
function.If
section.sort_by
is'date'
, the code sorts theposts
array either ascending or descending based onsection.reverse_order
by post's published date.If
section.enable_pagination
istrue
, the code paginates theposts
array using thepaginateCustom
function. Otherwise, the code limits the number of posts tosection.limit
using thelimit
function.The code then generates HTML to display the posts in the blog section, using the specified HTML tag, anchor, CSS classes, and styles. For each post, the code displays the post's title, author, and image.
The section's tag name is either section
or the section.html_tag
in the Advanced Tab fields if you have it set. The Advanced Tab fields also add an ID attribute and CSS Classes that you specify. You can also adjust the Bootstrap container type as well in this tab.
You can also adjust the spacing before and after using the switches from section.disable_top_spacing
, and section.disable_bottom_spacing
respectfully.
Note: This code requires additional context and information about the Twig functions used (e.g. collect
, whereRelation
, sortBy
, orderBy
(Similar to sortBy
), paginateCustom
, page
, resize
, etc.) to fully understand the implementation.
Files Used
The following files are used to display this content
builder/blog/*
included in thebuilder.yaml
filebuilder/section/posts.htm
partial used to display Blog Posts
Last updated