• Resolved kongkang

    (@kongkang)


    I want to make the_excerpt characters can be an any characters.

    Example template structure

    First loop = the_excerpt() limit chars – 100
    Second loop = the_excerpt() limit chars – 200
    Third loop = the_excerpt() limit chars – 300

    How to do that?

Viewing 6 replies - 16 through 21 (of 21 total)
  • there is never ‘the only way’ – this is just one possible way to do it.
    the above function is closely adapted from the actual code in the ‘wp_trim_excerpt()’ function in the wordpress core files.

    as for stripping the html tags – a link to a live site with an example to ilustrate where this function left unwanted tags might help.

    it could simply be that your previous function did not use the filter and therefore had no paragraph tags wrapping the excerpt.

    10x alchymyth for that great code!

    hey, i have this code working on a Starker Theme but not it’s not working with a Twenty Ten Theme. Is this possible?

    This is also regarding about the function the_excerpt()
    Starker Theme: Works fine!
    Twenty Ten Theme: It sucks!!!

    can anyone help me with this? thanks in advance mates.

    @abelboy
    can you explain in more detail, what is not working?

    how is the function or the_excerpt() not working in twenty ten?
    the automatic or the manual excerpt?

    (screenshots would be great, or html from the browser – for longer code please use a https://wordpress.pastebin.com/ )

    do you have any plugins installed and activated?
    what changes if you deactivate all plugins?
    (i just recently had at least two cases of plugins interfering with the excerpt)

    i checked in my local installation, and the function is working there with twenty ten

    ps:
    did you change all three ‘the_excerpts()’ in loop.php of twenty ten?

    @alchymyth

    /* THE_EXCERT */
    	function the_excerpt_dynamic($length) { // Outputs an excerpt of variable length (in characters)
    		global $post;
    		$text = $post->post_exerpt;
    		if ( '' == $text ) {
    			$text = get_the_content('');
    			$text = apply_filters('the_content', $text);
    			$text = str_replace(']]>', ']]>', $text);
    		}
    			$text = strip_shortcodes( $text ); // optional, recommended
    			$text = strip_tags($text); // use ' $text = strip_tags($text,'<p><a>'); ' to keep some formats; optional
    
    			$output = strlen($text);
    			if($output <= $length ) {
    				$text = substr($text,0,$length).' <div class="read_more"><a href="'. get_permalink($post->ID) . '" class="read_more_link" > Read More</a></div>';
    			}else {
    				$text = substr($text,0,$length).' [...]<div class="read_more"><a href="'. get_permalink($post->ID) . '" class="read_more_link" > Read More</a></div>';
    			}
    
    		echo apply_filters('the_excerpt',$text);
    	}

    returns “[…]” if the text is longer or just text if not…

    ok –
    might be useful for someone in the future …

Viewing 6 replies - 16 through 21 (of 21 total)
  • The topic ‘Dynamic the_excerpt’ is closed to new replies.