WordPress.org

Ready to get started?Download WordPress

Forums

Display Posts Shortcode
[resolved] How to add a read more link or [...] at the end of excerpt (11 posts)

  1. ismailrrr
    Member
    Posted 1 year ago #

    Hi,

    first of all thanks for this plugin which is so easy to use.

    i used the shortcode with excerpt of posts limited to 100 characters thanks to your code.

    my problem is that my excerpt get cut by 100 characters without any link or linked dots to the post. how can i modify the code to show something like [...] at the end of the excerpt?

    http://wordpress.org/extend/plugins/display-posts-shortcode/

  2. Bill Erickson
    Member
    Plugin Author

    Posted 1 year ago #

    I've updated the code snippet to add ... to the end of the excerpt. I changed this:

    be_truncate_phrase( get_the_excerpt(), 50 ) . '</p>'

    To this:

    be_truncate_phrase( get_the_excerpt(), 50 ) . '…</p>'

  3. ismailrrr
    Member
    Posted 1 year ago #

    Thanks a lot for your support! It helped!

  4. WebDi
    Member
    Posted 1 year ago #

    I apologize for jumping in this thread late, but this is what I'm looking for. I would like shorter excerpts with a read more link.

    Can you tell me where one should implement the code you posted in github?

    Thanks in advance!

  5. Bill Erickson
    Member
    Plugin Author

    Posted 1 year ago #

    The code can be added to your theme's functions.php file.

  6. Albuquerque web design
    Member
    Posted 1 year ago #

    This plugin is one of my favorite- I wish there is a way to add read more at the end of the excerpt. I dont want to modify the code that will be over written after the update

  7. cre8ivedm
    Member
    Posted 1 year ago #

    Sorry, but I am not sure of where to place the code:

    be_truncate_phrase( get_the_excerpt(), 50 ) . '…</p>'

    I can't find any code like that anywhere in my files.

  8. BlackHorseMedia
    Member
    Posted 1 year ago #

    I agree, this is an excellent plugin and I really appreciate the flexibility.

    I too would like a "read more" link or "continue reading." That's my 2 cents :)

  9. AJ
    Member
    Posted 11 months ago #

    This is what i did

    1. go to plugins, find Display posts shortcode press edit
    2. in the file "display-posts-shortcode/display-posts-shortcode.php" go to the bottom of the edit page and paste the code from this page > https://gist.github.com/billerickson/1179950
    3. where it says … (use ctrl-f), replace … with read more.. or whatever.

  10. Bill Erickson
    Member
    Plugin Author

    Posted 11 months ago #

    Please do not place that in the plugin itself. When the plugin is updated, the code will be lost.

    That code can go in your theme's functions.php file.

  11. ygiv
    Member
    Posted 11 months ago #

    Hi,
    If you change the code just a tiny bit you can add a "read more" with a link to the post at the end.

    /**
    * Edit our excerpt output
    *
    */
    
    /*
    add_filter( 'display_posts_shortcode_output', 'update_excerpt_format', 10, 7 );
    function update_excerpt_format( $output, $atts, $image, $title, $date, $excerpt, $inner_wrapper ) {
    
    	// First check if an excerpt is included by looking at the shortcode $atts
    	if ( $atts['include_excerpt'] )
    		// Now let's rebuild the excerpt with the read more link at the end
    		{
    		$read_more ='<p><a href="'.get_permalink() . '"> Read More...</a></p>';
                    //Now we can truncate
    		$excerpt = '<p><span class="excerpt">' . truncate_phrase( get_the_excerpt(), 150) . $read_more . '</span></p>';
    		}
    	else $excerpt = '';
    
    	// Now let's rebuild the output. Only the excerpt changed so we're using the original $image, $title, and $date
    	$output = '<' . $inner_wrapper . ' class="listing-item">' . $image . $title . $date . $excerpt . '</' . $inner_wrapper . '>';
    
    	// Finally we'll return the modified output
    	return $output;
    }
    */
    
    /**
     * Truncate Excerpt
     *
     */
    
    function truncate_phrase($phrase, $max_characters) {
    
    	$phrase = trim( $phrase );
    
    	if ( strlen($phrase) > $max_characters ) {
    
    		// Truncate $phrase to $max_characters + 1
    		$phrase = substr($phrase, 0, $max_characters + 1);
    
    		// Truncate to the last space in the truncated string.
    		$phrase = trim(substr($phrase, 0, strrpos($phrase, ' ')));
    
    	}
    
    	return $phrase;
    }

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic