Ordering blog posts by number of likes

Hi all,

I would like to sort blog posts by number of likes so that those posts with the most number of likes are displayed first.  Is there any way of doing this?

  • $options = [
        'type' => 'object',
        'subtypes' => ['blog'],
        'annotation_names' => ['likes'],
        'limit' => 10,
    ];
    
    echo elgg_get_entities_from_annotation_calculation($options);
  • Thanks RvR, I'm not sure where the php file that handles blog display is to be found.

  • You can test it on your test site by changing this file:

    mod\blog\views\default\resources\blog\all.php

    Use the above code instead of $content:

    $options = [
        'type' => 'object',
        'subtypes' => ['blog'],
        'annotation_names' => ['likes'],
        'limit' => 10,
    ];
    
    $content = elgg_get_entities_from_annotation_calculation($options);

    But there's a principle Don’t Modify Core.

    So it's a reason to start the developing your own custom plugin.

    Then you can put this code there.

Beginning Developers

Beginning Developers

This space is for newcomers, who wish to build a new plugin or to customize an existing one to their liking