Git Product home page Git Product logo

wp-ajax-like-button's Introduction

WP like button (ajax)

An ajax like button for Wordpress that can be used anywhere you want.

We have received a few questions about how we made the like button on Draft.im so I decided to make it available on Github. It's a Wordpress function that stores the IP address of those who like a post, post or custom post type post in a metabox. Simple yet effective.

##Include the php files note: these should be included in the functions.php

   <?php
   include_once('inc/like-metabox.php');
   include_once('inc/like-post.php');
   ?>

##Enqueue the js file note: this also has to be added to the functions.php file, if there's already a "wp_enqueue_scripts" present just add the script to that function

<?php
function enqueue_js_files() {

   wp_register_script( 'like-post', get_template_directory_uri() . '/js/like-post.js', array('jquery') ,false,'1.0',true);
   wp_enqueue_script( 'like-post' );

}
add_action( 'wp_enqueue_scripts', 'enqueue_js_files' );
?>

##Show the like link Make the like button show up in the front-end in it's most basic form, when the button has been clicked the js adds or removes the class "liked"

<a class="like" rel="<?php echo $post->ID; ?>"><?php echo likeCount($post->ID); ?> likes</a>

###Show the metabox on multiple post types Simply add new ones to the array and the metabox will show up on those pages. Just don't forget to add the like button/link in the front-end

// You can find this on line 9 in the like-metabox.php file
$show_on = array('post', 'pets');

wp-ajax-like-button's People

Contributors

daveyheuser avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.