Posts Section
Last updated
Last updated
The Posts Section Block displays posts from the entry type according to specified settings. The section's display behavior is controlled by the following settings:
settings.enable_blog
: Defined in the
section.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, if section.show_specific_items
is true
.
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, if section.filter_by_category
is true
.
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, if section.enable_pagination
is true
.
Based on these settings, the code is executing the following operations:
If section.show_specific_items
is true
, the code initializes an empty array posts
and pushes specific posts into it.
If section.filter_by_category
is true
, the code filters the posts
array to only include posts that belong to the specified category.
If section.sort_by
is 'title'
, the code sorts the posts
array either ascending or descending based on section.reverse_order
. If section.show_specific_items
is false
, the code sorts the posts using the orderBy
function, otherwise, the code sorts the posts using the sortBy
function.
If section.sort_by
is 'date'
, the code sorts the posts
array either ascending or descending based on section.reverse_order
by post's published date.
If section.enable_pagination
is true
, the code paginates the posts
array using the paginateCustom
function. Otherwise, the code limits the number of posts to section.limit
using the limit
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.
You can also adjust the spacing before and after using the switches from section.disable_top_spacing
, and section.disable_bottom_spacing
respectfully.
The following files are used to display this content
The section's tag name is either section
or the section.html_tag
in the 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.
Note: This code requires additional context and information about the Twig functions used (e.g. , , , orderBy
(Similar to sortBy
), , , , etc.) to fully understand the implementation.
included in the file
partial used to display Blog Posts