The Facebook Like Button is a very useful and rapidly popular social web marketing tool that can be applied to websites and webpages. By default, the Facebook's Like Button form will recommend a specific web page that is hard coded into the code snippet (which can be generated by Facebook's Like Button form).
Typepad users
now have the Facebook Like Button embedded as a core application, which has helped to generate a lot of traffic to blog websites based on a recent report by Typepad.
It is possible to publish a Facebook Like Button that references a dynamic Wordpress Post page rather than just making recommendations to the website in general.
How to reference the URL for a single Wordpress post
On the Wordpress post page template, below the snippet:
id="post-">,
you can print the page URL with the following code:
<?php the_permalink(); ?>
The above code snippet, will print the URL of that post page.
0
I want to create like button on posts that users can like that post... plz help
html5
php
3/28/2019 8:21:17 AM
Abhay
1 Answer
New Answer
Sort by:
+1
://Here is a code and explanation
https://stackoverflow.com/questions/7401141/php-mysql-like-button
Sudarshan Rai
Just a few days before, Facebook has launched Reactions, an extension of Like button. I succeeded in implementing the same in my WallScript 8, Build Your Own Social Network. Here is a quick and easy way to implement the Reactions using PHP,Jquery and PDO MySQL. It’s a basic idea of implementing the Reactions. Hope you enjoy the new Reactions for Like button..! Take a
quick look at the live demo.
Download Script Live Demo
Database Design To build the message like reaction system, you have to create four tables such as Users, Messages, Message_Like and Reactions. This following image generated by using Mysql Workbench tool.
Users Table
User table contains all the users registration details.
CREATE
TABLE `users` ( `uid` int NOT NULL PRIMARY KEYAUTO_INCREMENT , `username` varchar(25) NOT NULL UNIQUE, `password` varchar(50) NOT NULL , `email` varchar(100) NOT NULL, `name` varchar(100) NOT NULL, `profile_pic` varchar(200) NOT NULL, );
Data will store in following way,
here the password data PHP login script with PDO and HASH encryption.
Users
Messages Table
This table contains user status messages data. Here uid_fk is the FOREIGN KEY to REFERENCES users.uid
CREATE TABLE `messages` ( `msg_id` int(11) NOT NULL PRIMARY KEYAUTO_INCREMENT, `message`
varchar(200) NOT NULL, `uid_fk` int(11) NOT NULL, `like_count` int(11) DEFAULT NULL, `created` int(11) DEFAULT NULL, FOREIGN KEY (uid_fk)REFERENCESusers(uid) );
Messages
Reactions Table
This table contains reaction data names.
CREATE TABLE reactions( 'rid' INT NOT
NULL PRIMARY KEYAUTO_INCREMENT, 'name' VARCHAR(45) NOT NULL );
Reactions
Message Like Table
Contains all user message likes relation data. Here uid_fk is FOREIGN KEY to REFERENCES users.uid, rid_fk is FOREIGN KEY to REFERENCES reactions.rid and msg_id_fk is FOREIGN KEY to REFERENCES messages.msg_id
CREATE TABLE `message_like` (
`like_id` int(11) NOT NULL PRIMARY KEYAUTO_INCREMENT, `msg_id_fk` int(11), `uid_fk` int(11) NOT NULL, `created` int(11) NOT NULL, `rid_fk` int(11) NOT NULL, FOREIGN KEY (uid_fk) REFERENCESusers(uid), FOREIGN KEY (msg_id_fk) REFERENCES
messages(msg_id), FOREIGN KEY (rid_fk) REFERENCES reactions(rid) );
message_like JavaScript Libraries You have to include following JavaScript libraries. I have modified jquery tooltipster plugin for reactions popup.
Jquery Code Applying reaction tooltipster to the anchor tag. Tipsy plugin for reaction name tool tip.
$(document).ready(function() { //Black tooltip for reaction icons. $(".likeTypeAction").tipsy({gravity: 's',live: true});
//Reactions popup on mouseover
$(".reaction").livequery(function () { //Reactions HTML Content var reactionsCode=''+ ''+ ''+ ''+
''+ ''+ ''+ '';
Like Ajax Contains javascript code. $("body").on('click','.likeTypeAction', function(){}- here likeTypeAction is the class name of the reaction icon tag. Using $(this).parent().parent().attr("id") calling
icon tag message ID value.
/*Reaction*/ $("body").on("click",".likeTypeAction",function() { var reactionType=$(this).attr("data-reaction"); var reactionName=$(this).attr("original-title"); var rel=$(this).parent().parent().attr("rel"); var x=$(this). parent().parent().attr("id"); var sid=x.split("reaction"); var msg_id=sid[1];
var htmlData=''+reactionName+''; var dataString = 'msg_id='+ msg_id +'&rid='+reactionType;
Unlike Ajax Contains javascript code. $("body").on('click','.unLike', function(){}- here unLike is the class name of the unlike anchor tag. Using $(this).attr("id") calling anchor tag message ID value.
$("body").on("click",".unLike",function() { var reactionType='1'; var x=$(this).attr("id"); var sid=x.split("like"); var msg_id=sid[1]; var dataString = 'msg_id='+ msg_id +'&rid='+reactionType; var htmlData='Like'; $.ajax({ type: "POST", url: 'ajaxReaction.php', data: dataString, cache: false, beforeSend: function(){}, success:
function(html) { if(parseInt(html)==2) { $("#like"+msg_id).html(htmlData).addClass('reaction').addClass('tooltipstered').removeClass('unLike'); } } });
returnfalse; });
index.php Contains PHP and HTML code, displaying all of the user updates by calling $feed->newsFeed();