Show Excerpt With Thumbnail in Event List View

Home Forums Calendar Products Events Calendar PRO Show Excerpt With Thumbnail in Event List View

Viewing 15 posts - 1 through 15 (of 15 total)
  • Author
    Posts
  • #30747
    Jordan Polon
    Participant

    Hello-

    I wanted to limit the characters shown in the event list, and I followed the instructions found here: https://theeventscalendar.com/support/forums/topic/list-php-to-show-excerpt-instead-of-full-event-post/

    It worked perfectly, except it also removed the image thumbnails. Is there a way to limit the number of characters shown and still have the image?

    #30754
    Barry
    Member

    You can certainly limit the number of words. Where this piece of code is used (in Mike’s example):

    TribeEvents::truncate($post->post_excerpt)

    You can add an extra parameter to specify how many words ought to be used (else it defaults to 44):

    TribeEvents::truncate($post->post_excerpt, 100)

    This tutorial explains how to add thumbnails to the next event widget. In essence though you should be able to borrow the Add Thumbnail Code from the start of that tutorial and work it into your custom list template.

    #30765
    Jordan Polon
    Participant

    Thanks for the quick response. I’m wonderng if you could tell me how to change the original php:

    to truncate the post. The images displayed perfectly then. Is there something in between what’s above and what’s down here:
    post_excerpt) : TribeEvents::truncate(get_the_content(), 30); ?> that will leave the images as they were?

    #30769
    Jordan Polon
    Participant

    The original was:

    The new is:
    post_excerpt) : TribeEvents::truncate(get_the_content(), 30); ?>

    Sorry that didn’t show up before.

    #30770
    Jordan Polon
    Participant

    Trying again with the original:

    The new is:
    post_excerpt) : TribeEvents::truncate(get_the_content(), 30); ?>

    Sorry that didn\’t show up before.

    #30772
    Barry
    Member

    Hi Tara – you will need to use Pastebin or Gist (or a similar service) to share code in the forum, I’m afraid.

    #30780
    Jordan Polon
    Participant

    Just realized that. Sigh.

    #30783
    Barry
    Member

    Yep, sorry! We’re aware it’s a pain and some changes are in the works, but for the time being using Pastebin/Gist etc is the best workaround we can suggest :-/

    #30786
    Jordan Polon
    Participant

    So this showed the images in the event list, perfectly: http://pastebin.com/r5mjvgny
    This is what I am using now: http://pastebin.com/V1RcbQvG
    Is there something I could have done to just truncate the text, instead of doing what I did? The other option changes the styling, etc.

    #30840
    Barry
    Member

    Oh … I think I see now: in your scenario, are the images actually inside the content, rather than being designated post featured images?

    #30841
    Jordan Polon
    Participant

    Yes! That’s exactly it. (And the new WP media uploader is a pain!) Is there a workaround for just truncation of the text?

    #30849
    Barry
    Member

    Well, I’m not sure there is an easy way to automate this and still retain images in this fashion … unless you switch to using post thumbs (featured images) and work in code from the tutorial I linked to in my first reply.

    The problem is, what looks like an image in the visual post editor is actually a bit of code like this:

    <img src="http://website.com/wp-content/uploads/2013/01/my-aunt-bessy-and-her-stuffed-giraffe_1024x800.png" alt="Old photo of my Aunt Bessy holding her stuffed giraffe, which Great Uncle Sim won in the 1908 Summer Fete during the Klondyke Gold Rush" title="What a lovely giraffe toy!" />

    So if we limit the number of characters, clearly we don’t want to include the many characters that make up an image tag. A further complication is, what if you have emboldened text, italicized it, both of those and/or you have applied other effects? That also means further tags are going to be present in the text.

    The parser would have to be sufficiently complex to deal with all of that and be able to neatly close off each HTML element in the correct order, especially if the cut off point was half way through a set of nested elements.

    For that reason, the truncate() method simply dispenses of tags and so I’d recommend the use of post thumbs instead of trying to display a shortened piece of content that retains images in the post.

    Hope that makes sense!

    #31003
    Jordan Polon
    Participant

    That does. Thanks very much.

    #31037
    Barry
    Member

    No problem 🙂

    #978435
    Support Droid
    Keymaster

    This topic has not been active for quite some time and will now be closed.

    If you still need assistance please simply open a new topic (linking to this one if necessary)
    and one of the team will be only too happy to help.

Viewing 15 posts - 1 through 15 (of 15 total)
  • The topic ‘Show Excerpt With Thumbnail in Event List View’ is closed to new replies.