• Resolved aseenus

    (@aseenus)


    On one of my sites I got the excerpt working perfectly however the theme on another site I’m working on is really drilling me!

    On the site that works I put this into the functions

    <?php
    function excerpt_ellipse($text) {
       return str_replace('[...]', ' <a href="'.get_permalink().'">More ?</a>', $text); }
    add_filter('the_excerpt', 'excerpt_ellipse');
    ?>

    and it works fine but on this site the functions is a little messed up because I’m not using a custom theme but a theme I just downloaded and this is whats in the functions..

    <?php if ( function_exists('register_sidebar') )
    {
    register_sidebar(array('name' => 'Sidebar Top','before_widget' => '','after_widget' => '','before_title' => '<h3>','after_title' => '</h3>'));
    register_sidebar(array('name' => 'Sidebar Left','before_widget' => '','after_widget' => '','before_title' => '<h3>','after_title' => '</h3>'));
    register_sidebar(array('name' => 'Sidebar Right','before_widget' => '','after_widget' => '','before_title' => '<h3>','after_title' => '</h3>'));
    register_sidebar(array('name' => 'Sidebar Bottom','before_widget' => '','after_widget' => '','before_title' => '<h3>','after_title' => '</h3>'));
    register_sidebar(array('name' => 'Footer Left','before_widget' => '','after_widget' => '','before_title' => '<h3>','after_title' => '</h3>'));
    register_sidebar(array('name' => 'Footer Center','before_widget' => '','after_widget' => '','before_title' => '<h3>','after_title' => '</h3>'));
    register_sidebar(array('name' => 'Footer Right','before_widget' => '','after_widget' => '','before_title' => '<h3>','after_title' => '</h3>'));
    } 
    
    remove_filter('get_the_excerpt', 'wp_trim_excerpt');
    add_filter('get_the_excerpt', 'custom_trim_excerpt');
    
    remove_filter('get_the_excerpt', 'wp_trim_excerpt');
    add_filter('get_the_excerpt', 'custom_trim_excerpt');
    
    function custom_trim_excerpt($text) { // Fakes an excerpt if needed
    global $post;
    	if ( '' == $text ) {
    		$text = get_the_content('');
    
    		$text = strip_shortcodes( $text );
    
    		$text = apply_filters('the_content', $text);
    		$text = str_replace(']]>', ']]>', $text);
    		$text = strip_tags($text);
    		$excerpt_length = apply_filters('excerpt_length', 90);
    		$words = explode(' ', $text, $excerpt_length + 1);
    		if (count($words) > $excerpt_length) {
    			array_pop($words);
    			array_push($words, '...');
    			$text = implode(' ', $words);
    		}
    	}
    	return $text;
    }
    
    ?>

    I realize that here array_push($words, '...'); is where the more part is however how can I make it like the other site where it does not only display dots or words but it also links into the post.

    Thank you in advance!

Viewing 9 replies - 1 through 9 (of 9 total)
  • have you tried to put:
    $text = str_replace('[...]', ' <a href="'.get_permalink().'">More ?</a>', $text);
    after:
    $text = implode(' ', $words);

    Thread Starter aseenus

    (@aseenus)

    I tried this:

    array_pop($words);
    			array_push($words, '...');
    			$text = implode(' ', $words);
                            $text = str_replace('[...]', ' <a href="'.get_permalink().'">More ?</a>', $text);

    Didn’t work ??

    hi, i gave you the wrong string to replace – the array_push($words,, '...'); actually does not have the square brackets –

    could be worth another try:

    $text = str_replace('...', ' <a href="'.get_permalink().'">More ?</a>', $text);

    Thread Starter aseenus

    (@aseenus)

    I just tried that alch, it took away the … at the end of posts and made nothing be there instead :S

    Oh You can see in the tab writing posts, and in posting form you can see the button have name”excerpt”

    Thread Starter aseenus

    (@aseenus)

    Oh You can see in the tab writing posts, and in posting form you can see the button have name”excerpt”

    What? In the writing section I don’t see anything with ‘excerpt”

    i installed the filter on my blog, and it works — i know this is no help, really ??
    what puzzles me the most, is that the str_replace just took the … out without putting anything into place??
    instead of replacing the string, what about putting it into the $text at the point of ‘array_push’?

    function custom_trim_excerpt($text) { // Fakes an excerpt if needed
    global $post;
    
    	if ( '' == $text ) {
    		$text = get_the_content('');
    
    		$text = strip_shortcodes( $text );
    
    		$text = apply_filters('the_content', $text);
    		$text = str_replace(']]>', ']]>', $text);
    		$text = strip_tags($text);
    		$excerpt_length = apply_filters('excerpt_length', 75);
    		$words = explode(' ', $text, $excerpt_length + 1);
    		if (count($words) > $excerpt_length) {
    			array_pop($words);
    			array_push($words, ' <a href="'.get_permalink().'">More ?</a>');
    			$text = implode(' ', $words);
    		}
    	}
    	return $text;
    }

    Thread Starter aseenus

    (@aseenus)

    That worked, Thank you everyone for your help and effort, much appreciated ??

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘How to make excerpt say ‘More…’’ is closed to new replies.