This module displays comments newest first or oldest first by date on a per content type basis. It is a port of the Drupal 7 Comment Sort Weight module, with a fix for a permalink/pagination issue the original module did not address.
-
Install this module using the official Backdrop CMS instructions at https://docs.backdropcms.org/documentation/extend-with-modules.
-
Configure content types (
admin/structure/types/manage/[content_type]), go to Comment settings and check the box Sort comments by weight for options.
Per content type, the module lets you configure:
- Whether comments use a custom display order at all.
- Newest-first or oldest-first for root-level comments.
- Whether replies under each comment should also reverse, or keep their default oldest-first order regardless of the root setting.
A comment_sort_weight table stores one precomputed weight value per
comment, built by flattening the comment tree in the configured order.
hook_query_TAG_alter() targets Backdrop's comment_filter query tag in
comment_get_thread() and swaps in an ORDER BY on that weight column for
threaded listings, or a direct ASC/DESC swap on c.created for flat listings.
The table is resynced on comment insert/update/delete, and in bulk via a batch operation when a content type's settings are saved.
To correct comment permalinks or pager-page calculation when the sort order is
reversed this module computes the comment's correct page via
comment_sort_weight_get_display_ordinal(), querying the weight table
directly with no need for branching on sort direction since it's baked into the
weight at write time, and uses a backdrop_goto() redirect to
node/[nid]?page=[n]#comment-[cid] to avoid bypassing Backdrop's layout system;
matching the fix that was merged for the Backdrop forum Permalinks issue.
- Views integration. This was ported from the Drupal 7 module as
comment_sort_weight.views.inc, exposing theweightcolumn as a sortable/filterable/field-able Views column viahook_views_data(). Note: this only helps custom Views-based comment listings (e.g. a "recent comments" block) - it is a separate mechanism from thehook_query_TAG_alter()in this module that applies to the default comment display for a content type node, which doesn't go through Views at all.
Additional documentation is located in the Wiki.
- Seeking additional maintainers.
This project is GPL v2 software. See the LICENSE.txt file in this directory for complete text.