WordPress.org

Ready to get started?Download WordPress

Forums

Events Manager
[resolved] limiting text for event manager without using (19 posts)

  1. gavimobile
    Member
    Posted 2 years ago #

    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.

    http://wordpress.org/extend/plugins/events-manager/

  2. gavimobile
    Member
    Posted 2 years ago #

    if you have images which you want to remove from the output, you may want to add this line
    $replace = preg_replace('/<img[^>]+./','', $replace);
    just below
    $replace = $this->post_content;
    and above
    if($result == "#_MYEXCERPT"){

  3. Marcus
    NetWebLogic Support
    Plugin Author

    Posted 2 years ago #

    thanks for contributing, but as you very well know, modifying the core plugin is naughty :)

    given you managed to do this, you might find this useful: http://wp-events-plugin.com/tutorials/modifying-placeholder-default-information/

    that way you can override the placeholder without touching our plugin

  4. gavimobile
    Member
    Posted 2 years ago #

    Marcus, Your absolutely right. I'm going to try and play around with that tomorrow
    Thanks for your prompt response

  5. trymbill
    Member
    Posted 2 years ago #

    Marcus, would that then be em_eventexcerpt_output_placeholder for the #_EVENTEXCERPT? Can't find anything about it online and after searching your website I didn't find anything.

  6. trymbill
    Member
    Posted 2 years ago #

    Ah, or em_event_output_placeholder?

  7. agelonwl
    Member
    Posted 2 years ago #

    @trymbill

    please see this link to modify placeholder - http://wp-events-plugin.com/tutorials/modifying-placeholder-default-information/

    *replacing location with event

  8. gavimobile
    Member
    Posted 2 years ago #

    i got it folks! i will provide you with my example of how i successfully created the custom placeholder. the example in the links were a bit confusing for me.

    here we go, just add the code to your functions.php file. no need to edit the plugin as we all agreed was a bad idea.

    //creating a custom placeholder
    //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); // change the name of the function from em_event_output_placeholder to em_events_something
    function my_em_styles_placeholders($replace, $EM_Event, $result){ //make sure you change the name of the function to em_events_something
    	global $wp_query, $wp_rewrite;
    	switch( $result ){
    		case '#_MYEXCERPT': // name of the placeholder
    			$replace = $EM_Event->output("#_EVENTNOTES"); //lets retrieve the original event data so we can modify it
    			$replace = preg_replace('/<img[^>]+./','', $replace); // make the modification of taking out any images
    			if($result == "#_MYEXCERPT"){  //heres what we are goign to do if the placeholder has been found
    				$length = 25; //length of word for (the excerpt)
    				$replace = implode(' ',array_slice(explode(' ', $replace),0,$length)); //apply the length amount to the output
    				$replace = $replace . '...'; //add 3 periods after lenth has been reached
    			}
    		break; // end the case
    	}
    	return $replace; //output the placeholder
    }

    would love to know if this was helpful to someone

  9. Marcus
    NetWebLogic Support
    Plugin Author

    Posted 2 years ago #

    looks good, thx for sharing

  10. gavimobile
    Member
    Posted 2 years ago #

    Thanks for the feedback abd inspiration Marcus!

  11. gmorley
    Member
    Posted 2 years ago #

    Fantastic solution, thank you so much! Would have taken me hours to get this sorted without you. Much appreciated, Gavin.

  12. gmorley
    Member
    Posted 2 years ago #

    I made a small change to your script, because it was adding the ... to the end of the ones that were already short enough or excerpts. I set it to check if the excerpt was already shorter than 25 words, and if so it will leave it alone:

    //creating a custom placeholder
    //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 '#_MYEXCERPT': // name of the placeholder
    			$replace = $EM_Event->output("#_EVENTEXCERPT"); //lets retrieve the original event data so we can modify it
    			$replace = preg_replace('/<img[^>]+./','', $replace); // make the modification of taking out any images
    			if($result == "#_MYEXCERPT"){  //heres what we are goign to do if the placeholder has been found
    				if ( str_word_count($replace) > 25 ) {
    					$length = 25; //length of word for (the excerpt)
    					$replace = implode(' ',array_slice(explode(' ', $replace),0,$length)); //apply the length amount to the output
    					$replace = $replace . '... '; //add 3 periods after lenth has been reached
    				}
    			}
    		break; // end the case
    	}
    	return $replace; //output the placeholder
    }
  13. gavimobile
    Member
    Posted 2 years ago #

    Glad I Was helpful! Seems like you got the hang of it! Thanks for your additional example! I hope someone else may find it helpful!

  14. caburris
    Member
    Posted 1 year ago #

    Thanks for the excellent code, this is exactly what I was looking for and you saved me a couple of hours. You're a hero!

  15. gavimobile
    Member
    Posted 1 year ago #

    like!!! glad i was able to help!

  16. audunmb
    Member
    Posted 1 year ago #

    Thanks for sharing the code!

    This should replace the excerpt-code used now IMO

  17. Mickey Kay
    Member
    Posted 1 year ago #

    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
    }

  18. Mickey Kay
    Member
    Posted 1 year ago #

    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
    }
  19. Marcus
    NetWebLogic Support
    Plugin Author

    Posted 1 year ago #

    I've noted this page down for reference.

    @McGuive7, you may want to consider using force_balance_tags() - http://codex.wordpress.org/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!

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic