Home › Forums › Calendar Products › Community Events › Ampersand causing display errors when used in event summary and list widget
- This topic has 8 replies, 2 voices, and was last updated 10 years, 3 months ago by
Barry.
-
AuthorPosts
-
January 13, 2016 at 8:30 am #1055334
Ian
ParticipantAn 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.

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

I am using a Themify theme and have not tested this with a default WordPress theme.
January 13, 2016 at 1:46 pm #1055559Barry
MemberHi 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!
January 13, 2016 at 4:07 pm #1055657Ian
ParticipantWell – 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&zzzzzzzzzzzzzzzzzzzzzNG
zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz&zzzzzzzzzzzzzzzzzzzzzzzOK
zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz&zzzzzzzzzzzzzzzzzzzzzzzzzOK
zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzbzzzzzzzzzzzzzzzzzzzzzzNG
zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz&zzzzzzzzzzzzzzzzzzzzzzzNG
zzzzzzzzzzzzzz&zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzNG
&zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzOK
zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzaJanuary 13, 2016 at 4:09 pm #1055661Ian
ParticipantThis reply is private.
January 13, 2016 at 4:33 pm #1055679Barry
MemberOrdinarily, 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!
January 14, 2016 at 10:21 am #1056114Ian
ParticipantYes, 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 )January 14, 2016 at 11:13 am #1056123Barry
MemberHi 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 🙂
January 15, 2016 at 2:17 pm #1056834Ian
ParticipantThis 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; ?>January 15, 2016 at 3:42 pm #1056862Barry
MemberAwesome – 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 🙂
-
AuthorPosts
- The topic ‘Ampersand causing display errors when used in event summary and list widget’ is closed to new replies.
