Forum Discussion

cristinaiftode's avatar
7 years ago

Post thumbnail

Hi everyone,

I'd like to display a specific image (thumbnail) for each post that doesn't have a teaser image added when the post was created. How can I do that? I'm using masonry message list component.

 

Thanks,

Cristina

 

  • Hi cristinaiftode

     

    If you are using the masonry view, you can upload a thumbnail image for a post via the 'Cover photo' option in the right rail. You can see this when you create/edit a post.

    Thanks,

    Srujana.

    • cristinaiftode's avatar
      cristinaiftode
      Adept

      thank you! The problem is that but I already have hundreds of posts without a cover images uploaded and I don't want to do this manually

      • luk's avatar
        luk
        Boss

        cristinaiftode I hear you, we had the same issue with a client that has a huge community that existed way before teasers, masonry component and cover photo's, what we did (for a completely custom "masonry view"-replacement component though) is parse a posts content and extract the first image via freemarker-regex ( the ?matches built-in) and use this as the teaser image (if present, otherwise either nothing or a default image). Be careful with emojis though =), if you don't filter them out (you can, they have a specific URL-path) you'll end up with huge emojis as "post"-images, looks funny, especially the vomiting one!

         

        If you want to use the default masonry view (with all its flaws) and do something like this, you could build an endpoint that you provide with a message id, it would then go and parse the body/content text of that message for images and return the first one. You would call that endpoint with jQuery/AJAX for each post after the masonry view has loaded and inject the image afterwards. You could run into issues though because the height of every block where you inject an image into would change and that could mess up the masonry layout which usually relies on javascript as well (which has to calculate the top position based on the height of all blocks -> you can see the problem with changing height probably)...but yeah, that would be somewhat of an approach when using the default component.

      • VikasB's avatar
        VikasB
        Boss

        cristinaiftode
        OOTB -- Out of the box component in which lithium provides built-in functionality. So there is no standard way to set a default image. It can be done using CSS and Jquery if you want to add it to a single image but to do that you have to add extra script. So I would not suggest you go that way(not a preferred way)