Adding thumbnail preview to image files in the search results.

I really want to add thumbnail preview to image files in the search results.

Right now when you search for an image file the results are: The owners profile picture and the link with the title of the image.

Im trying to add a a thumbnail of the image instead of the title.

I've been looking at the
elgg_register_entity_type('object', 'file');
Line in the file_init() section but I have no idea how to display a thumbnail of the image instead of just the files title/link.

Any help would be great. Thanks!

  • The search plugin checks here: https://github.com/Elgg/Elgg/blob/2.0/mod/search/start.php#L349-L362 whether there are content specific search result views.

    So, create a custom plugin and add the file search/object/file.php to it. You can now modify that view to display the content you want. You can use this as an example: https://github.com/Elgg/Elgg/blob/2.0/mod/search/views/default/search/object/comment/entity.php

    (Starting from Elgg 2 you don't need a custom plugin, but you can instead simply add search/object/file.php to Elgg's installation directory.)

  • [Moderator: this comment was off-topic. It was moved to its own topic. Read it here.]

  • @juho
    Thank you so much for pointing me in the right direction. I was able to create a search/object/file.php and use the comments entity.php as a starting point. That worked great! thank you!

    I'm currently modifying the example entity.php but I'm having a tough time displaying the image thumbnail. I've added:

    $item = $vars['item'];
    $object = $item->getObjectEntity();
    $preview_size = 'large';

    $attachments = elgg_view_entity_icon($object, $preview_size, array(
    'img_class' => 'elgg-photo-river',
    'is_trusted' => true,
    ));

    Then I call $attachments in the search results but its not working. I'm sure I'm missing something and I'm probably over simplifying.

  • @juho

    Never mind I got it. I just stole the entity view in file/views/default/icon/object/file.php and that worked great. Thanks again for helping me out! Much appreciated!

  • Elgg 2.0.x

    Hi. Perharps these codes will help you..

    Preview in activiy page :

    Edit /var/www/elgg/mod/file/views/default/river/object/file/create.php :

    echo elgg_view('river/elements/layout', array(
    	'item' => $item,
    	'message' => $excerpt,
    	'attachments' => elgg_view_entity_icon($object, 'medium'),
    ));

    Preview in comments :

    Edit /var/www/elgg/vendor/elgg/elgg/views/default/river/object/comment/create.php :

    echo elgg_view('river/elements/layout', array(
    	'item' => $vars['item'],
    	'message' => elgg_get_excerpt($comment->description),
    	'summary' => $summary,
    	'attachments' => elgg_view_entity_icon($target, 'medium'),
    ));