Ampersand causing display errors when used in event summary and list widget

Home Forums Calendar Products Community Events Ampersand causing display errors when used in event summary and list widget

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #1055334
    Ian
    Participant

    An odd one: I find that IN CERTAIN CIRCUMSTANCES an ampersand ( & ) in an ‘excerpt’ field causes list widget display to corrupt.

    In the following example the ‘&’ between the words ‘History & Philosophy’ is causing a problem with a photo, which should be in a sidebar top right of the page displaying underneath the list. When replaced with the word ‘and’ the list is correctly displayed.

    Authur Miller

    HOWEVER if the summary text in the SAME entry is edited to have an entirely different summary which includes an ‘&’ there is no problem!!

    Anne Oakley

    I am using a Themify theme and have not tested this with a default WordPress theme.

    • This topic was modified 10 years, 3 months ago by Ian.
    • This topic was modified 10 years, 3 months ago by Ian.
    • This topic was modified 10 years, 3 months ago by Ian.
    #1055559
    Barry
    Member

    Hi Ian,

    That’s an odd problem!

    Could you provide a URL where I can observe this first-hand (by private reply if you prefer)?

    Thanks!

    #1055657
    Ian
    Participant

    Well – I have run some more tests and it seems as though the problem is when there are between 65 and 66 characters in whatever is entered in the excerpt field with one of the characters being an ampersand.

    OK
    zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz&zzzzzzzzzzzzzzzzzzzzz

    NG
    zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz&zzzzzzzzzzzzzzzzzzzzzzz

    OK
    zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz&zzzzzzzzzzzzzzzzzzzzzzzzz

    OK
    zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzbzzzzzzzzzzzzzzzzzzzzzz

    NG
    zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz&zzzzzzzzzzzzzzzzzzzzzzz

    NG
    zzzzzzzzzzzzzz&zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz

    NG
    &zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz

    OK
    zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzza

    #1055661
    Ian
    Participant

    This reply is private.

    #1055679
    Barry
    Member

    Ordinarily, our list widget does not display the excerpt so I’m guessing you’ve customized it to some extent (I also see bits of markup that have been commented out) … can you share the custom template(s) you are using, via Pastebin, Gist or a similar service?

    If you have no knowledge of any such customizations, could you confirm with your theme vendor if perhaps they shipped a number of pre-built templates targeting our plugins?

    Thanks!

    #1056114
    Ian
    Participant

    Yes, I should have said I did a number of customisations to get the list to display as needed. The first three may be relevant.

    /../child-theme/functions.php ( see http://pastebin.com/dyUSRVsY )
    /../child-theme/tribe-events/widgets/list-widget.php ( see http://pastebin.com/jd3GGpmJ )
    /../child-theme/tribe-events/widgets/modules/single-event.php ( see http://pastebin.com/hAy8J9yc )
    /../child-theme/tribe-events/list/single-event.php ( see http://pastebin.com/BFxLFWiV )

    #1056123
    Barry
    Member

    Hi Ian,

    So in two of your templates (but for the problem at hand, widgets/modules/single-event.php is the one that matters) you do something along these lines:

    $excerp = tribe_events_get_the_excerpt();
    $printexcerp = substr ( $excerp , 0 , 75 );
    echo $printexcerp;

    The problem is that slicing the string to precisely 75 characters can break a number of things.

    It can, for instance, slice an HTML entity in half. It could also slice opening or closing HTML tags in half – and that is what seems to be behind the problem here (if you inspect the HTML source of one of the pages with this widget you’ll probably be able to identify exactly what I mean).

    To cut a long story short, I’d strongly recommend revising that section of code 🙂

    #1056834
    Ian
    Participant

    This seems to work I think…

    <?php
      // based on code by Chirp Internet
      $excerp = tribe_events_get_the_excerpt();
      $break = " ";
      $limit = 85;
      $pad = "...";
    
      // return with no change if string is shorter than $limit
      if(strlen($excerp) <= $limit) {
    		$printexcerp = $excerp;
      }else{
      	// is $break present between $limit and the end of the string?
      	if(false !== ($breakpoint = strpos($excerp, $break, $limit))) {
        	if($breakpoint < strlen($excerp) - 1) {
          		$printexcerp = substr($excerp, 0, $breakpoint) . $pad;
        	}
      	}
      }
    
      echo $printexcerp; 
    
    ?>
    • This reply was modified 10 years, 3 months ago by Ian.
    • This reply was modified 10 years, 3 months ago by Ian.
    • This reply was modified 10 years, 3 months ago by Ian.
    #1056862
    Barry
    Member

    Awesome – looks like you’re on track!

    There still seems to be some potential for it to cut the string after an element has opened but before it has closed, however it may be that isn’t a concern in your case.

    At any rate, since we’ve moved into the realm of custom coding here and as it looks like you’re on your way to a solution I’ll go ahead and close out this topic – thanks again for posting 🙂

Viewing 9 posts - 1 through 9 (of 9 total)
  • The topic ‘Ampersand causing display errors when used in event summary and list widget’ is closed to new replies.