• Resolved thail

    (@thail)


    <?php
    
    /**
     *
     * Class A5 Excerpt
     *
     * @ A5 Plugin Framework
     * Version: 1.0 beta
     *
     * Gets the excerpt of a post according to some parameters
     *
     * standard parameters: offset(=0), usertext, excerpt, count
     * additional parameters: class(classname), filter(boolean), shortcode(boolean), format(boolean), readmore_link(boolean),
     * readmore_text(string)
     *
     */
    
    class A5_Excerpt {
    
    	public static function text($args) {
    
    		extract($args);
    
    		$offset = (isset($offset)) ? $offset : 0;
    
    		$class = (!empty($class)) ? ' class ="'.$class.'"' : '';
    
    		$filter = (isset($filter)) ? $filter : false;
    
    		$shortcode = (isset($shortcode)) ? $shortcode : false;
    
    		$format = (isset($format)) ? $format : false;
    
    		if (!empty($usertext)) :
    
    			$output = $usertext;
    
    		else: 
    
    			if (!empty($excerpt)) :
    
    				$output = $excerpt;
    
    			else :
    
    				$excerpt_base = (empty($shortcode)) ? preg_replace('/\[caption(.*?)\[\/caption\]/', '', $content) : strip_shortcodes($content);
    
    				$text = (empty($format)) ? strip_tags(trim(preg_replace('/\s\s+/', ' ', str_replace(array("\r\n", "\n", "\r", "&nbsp;"), ' ', $excerpt_base)))) : preg_replace('#<img(.*?)/>#', '', $excerpt_base);
    
    				$text = preg_replace('/\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|$!:,.;]*[A-Z0-9+&@#\/%=~_|$]/i', '', $text);
    
    				$length = (isset($count)) ? $count : 15;
    				$dots = 'hello';
    				$style = (isset($type)) ? $type : 'sentences';
    
    				switch ($style) :
    
    					case 'words' :
    
    						$short = array_slice(explode(' ', $text), $offset, $length);
    
    						$output = trim(implode(' ', $short));
    
    						break;
    
    					case 'sentences' :
    						/*
    						$short = array_slice(preg_split("/([\t.!?:]+)/", $text, -1, PREG_SPLIT_DELIM_CAPTURE), $offset*2, $length*2);
    
    						$output = trim(implode($short)); */
    						$short = array_slice(explode(' ', $text), $offset, $length);
    						$output = trim(implode(' ', $short));
    						break;
    
    					case 'letters' :
    
    						$output = substr($text, $offset, $length);
    
    						break;
    
    					default :
    
    						$output = $text;
    
    				endswitch;
    
    			endif;
    
    		endif;
    
    		if (!empty($linespace)) :
    
    			$short=preg_split("/([\t.!?:]+)/", $output, -1, PREG_SPLIT_DELIM_CAPTURE);
    
    			$short[count($short)] = '';
    
    			foreach ($short as $key => $pieces) :
    
    				if (!($key % 2) && $key < (count($short)-1)) :
    
    					$tmpex[] = implode(array($short[$key], $short[$key+1]));
    
    				endif;
    
    			endforeach;
    
    			if (isset($tmpex)) $output = trim(implode('<br /><br />', $tmpex));
    
    		endif;
    
    		if (!empty($readmore)) $output.=' <a href="'.$link.'" title="'.$title.'"'.$class.'>'.$rmtext.'</a>';
    
    		$output = ($filter === true) ? apply_filters('the_excerpt', $output) : $output;
    
    		return $output;
    
    	}
    
    } // A5_Excerpt
    
    ?>

    Above code how its look like. please help me out to return 3 dots at the end of excerpt. Its very urgent.

    https://www.ads-software.com/plugins/post-feature-widget/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author tepelstreel

    (@tepelstreel)

    You just have to get the output of the function according to some parameters.

    The simplest would be something like that:

    $args = array(
    'readmore' => true
    )
    
    $excerpt = A5_Excerpt::text($args);

    which gives you the […] at the end.

    If you don’t want the [] around the dots, you just add the additional parameter ‘rmtext’ to the $args. The code would then look like that:

    $args = array(
    'readmore' => true,
    'rmtext' => '...'
    )
    
    $excerpt = A5_Excerpt::text($args);

    But it should be enough to just enter the text into the input field for the read more text in the widget.

    I hope that helped.

    Thread Starter thail

    (@thail)

    <?php
    
    /**
     *
     * Class A5 Excerpt
     *
     * @ A5 Plugin Framework
     * Version: 1.0 beta
     *
     * Gets the excerpt of a post according to some parameters
     *
     * standard parameters: offset(=0), usertext, excerpt, count
     * additional parameters: class(classname), filter(boolean), shortcode(boolean), format(boolean), readmore_link(boolean),
     * readmore_text(string)
     *
     */
    
    class A5_Excerpt {
    
    	public static function text($args) {
    
    		extract($args);
    
    		$offset = (isset($offset)) ? $offset : 0;
    
    		$class = (!empty($class)) ? ' class ="'.$class.'"' : '';
    
    		$filter = (isset($filter)) ? $filter : false;
    
    		$shortcode = (isset($shortcode)) ? $shortcode : false;
    
    		$format = (isset($format)) ? $format : false;
    
    		if (!empty($usertext)) :
    
    			$output = $usertext;
    
    		else: 
    
    			if (!empty($excerpt)) :
    
    				$output = $excerpt;
    
    			else :
    
    				$excerpt_base = (empty($shortcode)) ? preg_replace('/\[caption(.*?)\[\/caption\]/', '', $content) : strip_shortcodes($content);
    
    				$text = (empty($format)) ? strip_tags(trim(preg_replace('/\s\s+/', ' ', str_replace(array("\r\n", "\n", "\r", "&nbsp;"), ' ', $excerpt_base)))) : preg_replace('#<img(.*?)/>#', '', $excerpt_base);
    
    				$text = preg_replace('/\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|$!:,.;]*[A-Z0-9+&@#\/%=~_|$]/i', '', $text);
    
    				$length = (isset($count)) ? $count : 15;
    				$dots = 'hello';
    				$style = (isset($type)) ? $type : 'sentences';
    
    				switch ($style) :
    
    					case 'words' :
    
    						$short = array_slice(explode(' ', $text), $offset, $length);
    
    						$output = trim(implode(' ', $short));
    
    						break;
    
    					case 'sentences' :
    						/*
    						$short = array_slice(preg_split("/([\t.!?:]+)/", $text, -1, PREG_SPLIT_DELIM_CAPTURE), $offset*2, $length*2);
    
    						$output = trim(implode($short)); */
    						$short = array_slice(explode(' ', $text), $offset, $length);
    						$output = trim(implode(' ', $short));
    								$args = array(
    								'readmore' => true,
    								'rmtext' => '...'
    )
    
    $excerpt = A5_Excerpt::text($args);
    						break;
    
    					case 'letters' :
    
    						$output = substr($text, $offset, $length);
    
    						break;
    
    					default :
    
    						$output = $text;
    
    				endswitch;
    
    			endif;
    
    		endif;
    
    		if (!empty($linespace)) :
    
    			$short=preg_split("/([\t.!?:]+)/", $output, -1, PREG_SPLIT_DELIM_CAPTURE);
    
    			$short[count($short)] = '';
    
    			foreach ($short as $key => $pieces) :
    
    				if (!($key % 2) && $key < (count($short)-1)) :
    
    					$tmpex[] = implode(array($short[$key], $short[$key+1]));
    
    				endif;
    
    			endforeach;
    
    			if (isset($tmpex)) $output = trim(implode('<br /><br />', $tmpex));
    
    		endif;
    
    		if (!empty($readmore)) $output.=' <a href="'.$link.'" title="'.$title.'"'.$class.'>'.$rmtext.'</a>';
    
    		$output = ($filter === true) ? apply_filters('the_excerpt', $output) : $output;
    
    		return $output;
    
    	}
    
    } // A5_Excerpt
    
    ?>

    This throws an error! Parse error: syntax error, unexpected ‘$excerpt’ (T_VARIABLE.

    I’m kinda new to the php. Can you please guide me exactly where to put that piece of code . It will be appreciated. ??

    Plugin Author tepelstreel

    (@tepelstreel)

    Well, first of all you leave my code untouched. It’s a class in itself and the code, I wrote yesterday, you call from outside the class. Not from in the middle of the function.

    And as I mentioned before, the easiest way, to get your dots is just to use the settings of the widget.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘unable to return three dots at the end of excerpt.’ is closed to new replies.