Like Button - Docs

Easy way to add custom like button for your projects.

About

Like Button is JavaScript and PHP based script that allows you to add like functionality for your projects. It's easy to install and configure. I hope you'll be happy with your purchase, if no then please let me know, I'll be try to help as much as I can.

Demo

Which color do you like more?

For more examples, please check demo page.

Files structure

.
|---. assets
|   |--- style.css
|   |--- normalize.css
|   |--- jquery.css
|---. demo
|   |--- index.html
|---. docs
|   |--- index.html
|---. src
|   |--- autoloader.php
|   |--- config.php
|   |--- db.sql
|   |--- index.php
|   |--- LikeButton.css
|   |--- LikeButton.js
|   |---. Idered
|       |---. LikeButton
|           |--- LikeButton.php
|           |--- Storage
|           |--- Helpers
|           |--- Database

I've marked * files which you might want to change.

Installation

  1. Rename src directory to LikeButton and copy it to your project root.
  2. In file where you want to add like button, add this code in <head>:
    <link rel="stylesheet" href="/LikeButton/LikeButton.css">
  3. Before </body> add this code:
    <script src="//code.jquery.com/jquery-1.10.2.min.js"></script>
    <script src="/LikeButton/LikeButton.js"></script>
    <script>
        jQuery(document).ready(function() {
            $('.js-like').likeButton({
                url: '/LikeButton/'
            });
        });
    </script>
  4. Add button:
    <button class="js-like btn-like" data-item-id="1">Like</button>
    Important: each button needs to have unique id, to set it, use data-item-id attribute. If you want bind together two buttons then use the same id.

Configuration

HTML Attributes

<button class="js-like btn-like" data-item-id="1" data-url="http://example.com" data-title="Sample counter title">Like</button>

JavaScript

{
    url: '/LikeButton/',
    disableCounter: false,
    customCounter: 'btn-like-custom-counter',
    before: function(btn) {},
    after: function(btn, response) {}
}

PHP

You can find PHP configuration in config.php file:

Customization

Color schemes

There're 2 color schemes for inactive button:

There're 5 color schemes for active button:

Custom counter

To create custom counter use this:

<span class="btn-like-custom-counter" data-item-id="1"></span>

Set your data-item-id and script will handle the rest. You can change default btn-like-custom-counter class using JS customCounter setting.

PHP API

To use Like Button php api, you have to include main index.php file and load class:

include 'LikeButton/index.php';
use Idered\LikeButton\LikeButton;

You can now use api:

FAQ

Can I disable user to unlike?

Yes, you can, please check undo PHP option.

I'm using infinite scroll to add projects to my page, how do I update counter value?

Use this jQuery code:

$('.js-like').trigger('update');

Thanks for purchase!