• michapixel

    (@michapixel)


    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)
  • Thread Starter michapixel

    (@michapixel)

    i added "allowed" => '' to the $ns_options.
    and since you already used “strip_tags” i though it would be better to give is some more sense, so i put the $ns_options as 2nd argument in there, eg: $excerpt = explode('.', strip_tags(get_the_content(), $ns_options['allowed']), $ns_options['sentence']+1);

    Plugin Contributor christopherross

    (@christopherross)

    Thanks micha, would you be able to send me the changes via email (http://thisismyurl.com), I’m always keen to add additions to the code.

    Thread Starter michapixel

    (@michapixel)

    gosh, where on earth do you hide your email?

    Plugin Contributor christopherross

    (@christopherross)

    hm … sorry, it’s info@thisismyurl.com

    Thread Starter michapixel

    (@michapixel)

    just sent you an email containing the changed file.

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.