Are you a GenerateCustomer?

Do you have an active GP Premium or GenerateBlocks Pro license key?

Create a GenerateSupport account for GeneratePress and GenerateBlocks support in one dedicated place.

Create an account
Already have a GenerateSupport account? Login

Just browsing?

Feel free to browse the forums. Support for our free versions is provided on WordPress.org (GeneratePress, GenerateBlocks).

Want to become a premium user? Learn more below.

Query Loop for Comments?

  • I’m interested in creating new views of things like Latest Comments, Hot Topics, Most popular commenters, etc. on our front page.

    Is it possible to use a QL block to query comment data in this way? Any suggestions would be appreciated, thanks!

  • Hi Marty,

    What’s easily possible through custom code is to order the Query Loop by the most comments.

    Ordering posts by the most recent comments would be more complicated and out of our scope.

    Getting the users with the most comments is not a feature available in the GB Query Loop. You’ll need a custom code for this. I found this article which may help: https://www.isitwp.com/display-user-with-the-most-comments/

  • Appreciate the insight, thanks Fernando!

    > What’s easily possible through custom code is to order the Query Loop by the most comments.

    Could you share an example of code to do this, and does is using the QL block?

  • Add cu-query-loop-com to the class list of the Grid Block under the Query loop.

    Adding Custom Classes: https://wordpress.com/support/wordpress-editor/adding-additional-css-classes-to-blocks/

    Then, add this Snippet:

    add_filter( 'generateblocks_query_loop_args', function( $query_args, $attributes ) {
        if (
            ! empty( $attributes['className'] ) &&
            strpos( $attributes['className'], 'cu-query-loop-com' ) !== false
        ) {
            return array_merge( $query_args, array(
                'orderby' => 'comment_count',
                'order' => 'DESC',
            ) );
        }
    
        return $query_args;
    
    }, 10, 2 );

    Adding PHP: https://docs.generatepress.com/article/adding-php/#code-snippets

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.