A simple and efficient post like system for WordPress.
PHP CSS JavaScript
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
css Major Update Oct 29, 2015
js Update simple-likes-public.js Apr 13, 2016
README.md We will release as soon as possible Mar 24, 2016
composer.json Update composer.json Nov 2, 2015
post-like.php Changed order of ajax url Apr 13, 2016

README.md

WordPress-Post-Like-System

A simple and efficient post like system for WordPress. View the demo.

It's a bit outdated at this point, but check out this post on Sven Hofmann's site for more information.

Four Steps to Glory

  1. Add the CSS to your theme's main stylesheet.
  2. Add the javascript file to your theme's js folder (if it exists). If there is no js folder at your theme's root level, create one and add simple-likes-public.js to it.
  3. Add the contents of post-like.php to your theme's functions.php file.
  4. Output the button by doing the following:
    • Add the button to any posts in your theme by adding the following function, within the loopecho get_simple_likes_button( get_the_ID() );
    • Add the button to any comments in your theme by making sure the second parameter in the button function is set to "1" — echo get_simple_likes_button( get_comment_ID(), 1 );
    • Include the [jmliker] shortcode in your posts

Upgrades

I've cleaned up a lot here, fixing a few errors, and making it easier to revise this system to suit your theme. Here are the highlights:
  • You can now add the button to comments.
  • You can now add multiple buttons for each post, and they will all update at once when you click any of them.
  • SVG icons, so no more icon fonts. In an effort to keep things light, the SVG has been added inline, with a simple html entity as a fallback. This way, we don't have to include a javascript fallback. The trade-off is that these inline icons are not cached. They are rather small, though. If you prefer to use Font Awesome or another icon solution, swap out the svgs in the get_liked_icon() and get_unliked_icon() functions with your own solution. Since it is a popular solution, I've included commented code for Font Awesome icons.
  • The button will now work with or without javascript. Hooray for graceful degradation!
  • All the text is now translatable. Find and replace 'YourThemesTextDomain' with your theme's text domain.
  • Number formatting now included. For example, a like count of "1,250" will output as "1.25K". If you would prefer a different number format, update sl_format_count(); to your preference.
  • Better IP address handling
  • The time of the post/comment like is now recorded as post/comment meta. This allows us to properly perform proper meta queries to determine which posts have the most likes for a given time period.

Removed

I've removed some functions and changed the way this system works a bit. None are breaking changes. These were for efficiency.
  • The functions that formerly appeared here to output most liked lists have been removed. Time-based retrieval of most liked lists (ex. "Most Popular Post This Week"), returned posts based on the time the post was published. This was inadequate — posts should have been returned based on the time the post was liked. If you should happen to need these older functions for some reason, they are still available in past versions.
  • We no longer store an array of liked posts in user meta. As time goes by, this can lead to inconsistencies if posts are deleted. I could have built a clean-up function to find and remove deleted post ids from user meta, but it made more sense to stop adding this data to user meta. Especially since these posts can be retrieved with a meta query for all posts that have the user's ID attached (see show_user_likes(); for this query).

Issues

This post like system is pretty simple, and does not have many moving parts. Some folks have encountered issues with AJAX-loaded content, and others have had some trouble with plugin conflicts. Feel free to open an issue if your stuck, and I will do my best to help you solve it.

Coming in November December January? Soon

We have been working hard on many updates to this system, two new plugins, and documentation. It's taking a bit longer than expected, so please bear with us. We are extending the plugin version for use with BuddyPress and bbPress as well! Here are a couple screenshots of the settings...

This Post Like System will soon be offered as a free and premium plugin. The free plugin will have everything the current system does, but will be easier to manage from the WordPress admin (no more implementation errors). The premium plugin will offer AJAX widgets for Most Liked Lists that will update & respond to likes without a screen refresh, and can be managed from the WordPress admin.