Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Add Facebook Like to Display Posts Shortcode plugin
<?php
/**
* 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
* @param $inner_wrapper string, what html element to wrap each post in (default is li)
* @return $output string, the modified markup for an individual post
*/
add_filter( 'display_posts_shortcode_output', 'be_display_posts_facebook', 10, 7 );
function be_display_posts_facebook( $output, $atts, $image, $title, $date, $excerpt, $inner_wrapper ) {
// 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 . '</span>';
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;
}
@jer0dh

This comment has been minimized.

Copy link

jer0dh commented Dec 19, 2014

Modifying this code and adding some javascript to my WordPress site, I was able to create a nifty grid formatted list of posts that could be filtered (by tags) using a dropdown box.

You write awesome code. Thank you!
Here's the link to my javascript
https://gist.github.com/864c5e7bf1b53c9e1ef1.git

@e-media

This comment has been minimized.

Copy link

e-media commented Oct 6, 2015

Hi @jer0dh. Is there a way to add alphabet numbers between posts that are being ordered?
My page is almost done, just need the alphabet numbers between the different ordering:
http://www.godwithus.co.za/preke

You will see there is an example below the first section, but this currently only uses tags.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.