Support » Plugins and Hacks » Get Better Excerpt » [Plugin: Get Better Excerpt] improvement over v 1.02

  • i added some simple additional arguments to satisfy my need of better controlling the output in regards of tags.

    function get_better_excerpt($options='') {
    
    	$ns_options = array(
                        "sentence" => false,
                        "words" => "20",
                        "before"  => "",
                        "after" => "",
    					"show" => false,
    					"skipexcerpt" => true,
    					"link" => false,
    					"trail" => " …",
    					"allowed" => ''
                       );
    
    	$options = explode("&",$options);
    
    	foreach ($options as $option) {
    
    		$parts = explode("=",$option);
    		$options[$parts[0]] = $parts[1];
    
    	}
    	if ($options['sentence']) {$ns_options['sentence'] = $options['sentence'];}
    	if ($options['words']) {$ns_options['words'] = $options['words'];}
    	if ($options['before']) {$ns_options['before'] = $options['before'];}
    	if ($options['after']) {$ns_options['after'] = $options['after'];}
    	if ($options['show']) {$ns_options['show'] = $options['show'];}
    	if ($options['skipexcerpt']) {$ns_options['skipexcerpt'] = $options['skipexcerpt'];}
    	if ($options['link']) {$ns_options['link'] = $options['link'];}
    	if ($options['allowed']) {$ns_options['allowed'] = $options['allowed'];}
    	if (isset($options['trail'])) {$ns_options['trail'] = $options['trail'];}
    
    	global $more;
    	$more = 1;
    	if ($ns_options['skipexcerpt']) {
    		if ($ns_options['sentence']) {
    			$excerpt = explode('.', strip_tags(get_the_content(), $ns_options['allowed']), $ns_options['sentence']+1);
    		} else {
    			$excerpt = explode(' ', strip_tags(get_the_content(), $ns_options['allowed']), $ns_options['words']+1);
    		}
    	} else {
    		if ($ns_options['sentence']) {
    			$excerpt = explode('.', strip_tags(get_the_excerpt(), $ns_options['allowed']), $ns_options['sentence']+1);
    		} else {
    			$excerpt = explode(' ', strip_tags(get_the_excerpt(), $ns_options['allowed']), $ns_options['words']+1);
    		}
    	}
    	array_pop($excerpt);
    	$excerpt = implode(" ",$excerpt);
    	$excerpt = $excerpt.$ns_options['trail'];
    
    	if ($link) {
    		$link = get_permalink();
    		$title = get_the_title();
    		$excerpt = "<a href='$link' title='$title'>".$excerpt."</a>";
    	}
    
    	$excerpt = $ns_options['before'].$excerpt.$ns_options['after'];
    
    	if ($show) {echo $excerpt;} else {return $excerpt;}
    }
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘[Plugin: Get Better Excerpt] improvement over v 1.02’ is closed to new replies.