How to maintain like button count across sessions

Hi,

I am trying to implement like button for every quote on my webpage,eg. 100 Like buttons on one page. I want to maintain a value for each of these like element seperately in such a way that everytime page loads it fetches the stored value,how can I define and update that variable.

I am using javascript and aware of session object to some extent, however not sure how it can be implemented exactly in this case.

I know like button code is available from fb, google+ etc, however the count can not be maintained seperately if two buttons are used on same page.I want multiple like buttons on a single page. Please let me know the easiest way for it.:confused:

Hi shiv.jad

I know this is possible because I’ve seen it myself and found a solution sometime back, though never ended up using it.
Unfortunately I don’t have the resources to hand as this was some time ago.

What I do remember is that you need to reference the like button ID or reference no. from that page and add it to the like button.
This means you can have multiple like buttons on the same page but all referencing a different ID (page).

Give it a try and let us know how you get on.
And remember, you only need the fb script once add it into your head or footer, don’t add it for every button just slow down your page.

Barry

So do you mean its possible with help of fb like button only i need to manipulate the code somehow or work on my code to provide seperate ref number to fb code?

So do you mean its possible with help of fb like button only i need to manipulate the code somehow…

In short yes, though you’ll need a unique ref no. for that quote which usually comes from the page the quote is on.

I might of slightly misunderstood your question.
What I suggest is based on each quote/article having its own page with its own fb like button, if your pulling these quotes from a database and just showing them randomly on the page, then not sure how this is done unfortunately.

This is the kind of thing I am talking about
http://stackoverflow.com/questions/11809161/how-to-put-multiple-facebook-like-buttons-with-counter-on-same-page

Barry

Well, yes that is what I want, however I am not clear with the solution there. I had already tried the fb plugin given in solution. I understand the link represents individual page for each element, and xfblike button code has to be placed where i want to place like button, however what is html5 button code? where it should be placed?

Also do i need to have as many actual pages as count of like buttons or will these be virtual links.

Somehow I feel writing own code(than using fb like) is more flexible provided its not affecting page load time. Any thoughts or experience?:x

Ignore the link I used that was just an example.

Simply put, each quote on the page should have something like:

<div>
<p>Quote 1</p>
<fb:like layout="button_count" show_faces="false" width="50" font="verdana"></fb:like>
</div>

<div>
<p>Quote 2</p>
<fb:like layout="button_count" show_faces="false" width="50" font="verdana"></fb:like>
</div>

<div>
<p>Quote 3</p>
<fb:like layout="button_count" show_faces="false" width="50" font="verdana"></fb:like>
</div>

And the script inside the head as mentioned earlier.

All you need then is to add the ref or id for that quote as an extra attribute, so it might look something like:

<fb:like layout="button_count" ref="85938098" show_faces="false" width="50" font="verdana"></fb:like>

Barry

Hi Barry,

First of all thanks for working with me on this. I tried both the solutions, the first solution from the stackoverflow link worked fine for me also with fb share button,however I found extra headache of creating seperate page for every quote.

I did it this way-
<div class=“fb-like” data-href=“‘.$thepage[http://www.quotesforeveryone.com/link2.html].’” data-send=“false” data-layout=“button_count” data-width=“90” data-show-faces=“false” data-font=“tahoma” style=“margin-left: auto; margin-right: auto; text-align: center;”>
“Old is gold.” <br>
<fb:like href=“http://www.quotesforeveryone.com/link2.html” send=“true” width=“450” show_faces=“false”></fb:like></div>

o/p of sharing page on FB

Link2 <this link points to newly created page for quote>
<mysite name>

What I will prefer now is instead of Link2, quote should be displayed and it should point to home page of my website instead of seperate page for quote. I tried different combinations for http field but no luck. (:

I tried the code given by you with ref field,however all likes are incrementing at the same time.(: Did u try this code yourself or am I mistaking something.

Did u try this code yourself or am I mistaking something.

The code I gave was just an example to guide you in the right direction. As I said, I wasn’t 100% sure of what was need to make everything work though I knew it was possible. I remember when I did it I just needed to reference the page/like button id, or something along those lines.

Like with most things, there is always a couple of ways to do it hopefully this has put you on the right track.
Try different scenarios yourself and test stuff then if all else fails come back.

Remember, you only learn by making mistakes. Good luck!
I’m signing off now.

Barry

I don’t know how JS itself will remember all the users’ Likes. Or is this being used by one computer? If this is being used by one computer/user, I would use localStorage for this.

If this is being used by a wide range of users on different computers, you’ll need a database solution to store the likes. In this case, you would set up a database consisting of a row for each quote containing an ID column and a Count column. Your quotes might as well be in a third column.

Each time a Like button is clicked, PHP will increment the correct row’s Count column according to the quote’s unique ID.

Each time the page is accessed, the PHP code will pull the current data from the DB.

It sounds like your website will contain repetitive pages. Therefore, I highly recommend the database route. As matter of fact, if you get Sitepoint’s PHP & MySQL: Novice to Ninja, you’ll get the complete source code for what you need, for the book goes carefully into how to build a Joke DB. You will simply use quotes instead of jokes, and apply your own CSS to style the output.

I could resolve this for myself. please visit quotesforeveryone.com to see implemented functionality.