WordPress.org

Forums

Display Posts Shortcode
[resolved] Plugin:display-posts-shortcode - Facebook like button at the end of excerpt (4 posts)

  1. Allanon27
    Member
    Posted 3 years ago #

    Hi Man,

    I really like Your display-posts-shortcode plugin! In fact I've just combined it with Fanpage Connect, and created a Facebook App.

    Can You include Facebook Like/Share button at the end of the excerpt? (like a new fb tag or something)

    Thanks in advance!

    Best Wishes,
    Matt

  2. Bill Erickson
    Member
    Plugin Author

    Posted 3 years ago #

    While I won't add that specific feature, I have added a filter that allows you to tweak the output however you want (update your plugin to 0.1.5).

    This would go in your theme's functions.php file. It's really only a few lines of code but I've added a lot of documentation so others can figure out what I'm doing and apply it to their scenario.

    /**
     * Add Facebook Button to Display Posts Shortcode plugin
     * @author Bill Erickson
     * @link http://wordpress.org/extend/plugins/display-posts-shortcode/
     * @link http://wordpress.org/support/topic/facebook-likeshare-button-at-the-end-of-excerpt
     *
     * @param $output string, the original markup for an individual post
     * @param $atts array, all the attributes passed to the shortcode
     * @param $image string, the image part of the output
     * @param $title string, the title part of the output
     * @param $date string, the date part of the output
     * @param $excerpt string, the excerpt part of the output
     * @return $output string, the modified markup for an individual post
     */
    
    add_filter( 'display_posts_shortcode_output', 'be_display_posts_facebook', 10, 6 );
    function be_display_posts_facebook( $output, $atts, $image, $title, $date, $excerpt ) {
    
    	// Here's the facebook code we'll be adding to the excerpt
    	$facebook = 'facebook code goes here';
    
    	// 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 facebook code at the end
    		$excerpt = ' - <span class="excerpt">' . get_the_excerpt() . $facebook;
    	else $excerpt = '';
    
    	// Now let's rebuild the output. Only the excerpt changed so we're using the original $image, $title, and $date
    	$output = '<li>' . $image . $title . $date . $excerpt . '</li>';
    
    	// Finally we'll return the modified output
    	return $output;
    }
  3. Allanon27
    Member
    Posted 3 years ago #

    All I can say is WOW! That was pretty fast! I will try this out right now! :)

  4. Bill Erickson
    Member
    Plugin Author

    Posted 3 years ago #

    Oops, I forgot to add a closing span to the end of the excerpt. You can see the updated code at the bottom of this post: http://www.billerickson.net/shortcode-to-display-posts/

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Display Posts Shortcode
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic