• Resolved gavimobile

    (@gavimobile)


    hi folks, i know its not recommended to edit plugins, however i was having trouble finding a way to limit the number of words with my event manager descriptions. i didnt want to use the <!–more–> option either, because i didnt want to confuse my client with using the <!–more–> option. if you are looking for a way to limit the text and #_EVENTEXCERPT OR #_EXCERPT is not what you are looking for, you can try adding this code to the em-events.php file at approx line 1233

    case '#_MYEXCERPT':
    					$replace = $this->post_content;
    					if($result == "#_MYEXCERPT"){
    						$length = 25;
    						$replace = implode(' ',array_slice(explode(' ', $replace),0,$length));
    						$replace = $replace.' ...';
    					}
    					break;

    now all you need to do is add #_MYEXCERPT and it will limit the
    amount of words being outputted in the description/notes. also change $length = 25 to the number of words you wish to output. i used 25 in this example. i really do hope this was helpful for you even though this may not be the recommended way of doing this because if there is an update, this change will be lost and have to be reapplied after each update. also if you have a better solution i would really love to hear it.

    https://www.ads-software.com/extend/plugins/events-manager/

Viewing 3 replies - 16 through 18 (of 18 total)
  • Hi there,

    Thanks so much for paving the way with this one. I’ve made a few additions to counter some weird behavior – other may or may not find them useful too:

    1. The excerpt accidentally terminating in the middle of a tag, thus leaving an unfinished tag in the output. The original code solved this problem for images, but I ran into the same problem with tags. The downside is that no tags show up in the excerpt. This works in my situation though.
    2. Outputting the ellipses (…) even when the actual excerpt is less than the specified character / word threshold.
    3. Switched to specifying a character limit instead of a word limit. This felt a bit more precise to me.

    Here’s the code, hope it helps:
    //create the filter. the website will search for our placeholder using this function
    add_filter('em_event_output_placeholder','my_em_styles_placeholders',1,3);
    function my_em_styles_placeholders($replace, $EM_Event, $result){
    global $wp_query, $wp_rewrite;
    switch( $result ){
    case '#_CUSTOMEXCERPT': // name of the placeholder
    $replace = $EM_Event->output("#_EVENTEXCERPT"); //lets retrieve the original event data so we can modify it
    $replace = preg_replace('/<[^>]+./','', $replace); // make the modification of taking out any images
    if($result == "#_CUSTOMEXCERPT"){ //heres what we are goign to do if the placeholder has been found

    if ( strlen($replace) > 120 ) {
    $length = 120; //length of word for (the excerpt)
    $replace = substr($replace,0,$length); //apply the length amount to the output
    }

    $replace = $replace . '... ';
    }
    break; // end the case
    }
    return $replace ; //output the placeholder
    }

    woops, here it looks better:

    //create the filter. the website will search for our placeholder using this function
    add_filter('em_event_output_placeholder','my_em_styles_placeholders',1,3);
    function my_em_styles_placeholders($replace, $EM_Event, $result){
      global $wp_query, $wp_rewrite;
      switch( $result ){
        case '#_CUSTOMEXCERPT': // name of the placeholder
          $replace = $EM_Event->output("#_EVENTEXCERPT"); //lets retrieve the original event data so we can modify it
          $replace = preg_replace('/<[^>]+./','', $replace); // make the modification of taking out any images
          if($result == "#_CUSTOMEXCERPT"){  //heres what we are goign to do if the placeholder has been found
    
            if ( strlen($replace) > 120 ) {
              $length = 120; //length of word for (the excerpt)
              $replace = substr($replace,0,$length); //apply the length amount to the output
            }
    
            $replace = $replace . '... ';
          }
        break; // end the case
      }
      return $replace ; //output the placeholder
    }
    Plugin Author Marcus (aka @msykes)

    (@netweblogic)

    I’ve noted this page down for reference.

    @mcguive7, you may want to consider using force_balance_tags() – https://codex.www.ads-software.com/Function_Reference/force_balance_tags

    If anyone has some sample text that is known to break the excerpt, that could be helpful when we do get round to testing/fixing this. Thanks!

Viewing 3 replies - 16 through 18 (of 18 total)
  • The topic ‘[Plugin: Events Manager] limiting text for event manager without using’ is closed to new replies.