Solved

Adding Facebook/Twitter Like Button to RSS Feed

Posted on 2011-09-02
4
2,207 Views
Last Modified: 2013-11-18
I stumbled across this RSS feed reader on w3schools.com.
http://www.w3schools.com/php/php_ajax_rss_reader.asp

It works great and I am able to add RSS-feeds without a problem. My question is, how do I add social media buttons such as Facebook Like or a Twitter button? For each story or news article, I would like my users to be able to share via Facebook or reTweet the story. How do I do this with w3schools code?
0
Comment
Question by:spoggles
  • 3
4 Comments
 
LVL 10

Expert Comment

by:ray-solomon
ID: 36509974
This is just a basic example.

In the example PHP file on w3schools, to add a facebook "LIKE" link, you can change this part:

//output elements from "<channel>"
echo("<p><a href='" . $channel_link
  . "'>" . $channel_title . "</a>");
echo("<br />");
echo($channel_desc . "</p>");

Open in new window


to this:

//output elements from "<channel>"
echo("<p><a href='" . $channel_link . "'>" . $channel_title . "</a>");
echo("<br /><a href='http://www.facebook.com/plugins/like.php?app_id=159397647477718&href=" . $channel_link ."' target='_blank'>Facebook Like</a><br />");
echo($channel_desc . "</p>");

Open in new window


As you can see, I added a new anchor tag element into the code that uses the $channel_link and made it part of the facebook url.
You can also make a facebook button and use that instead:
https://developers.facebook.com/docs/reference/plugins/like/

The same concept applies to twitter or any other social site. Use their public API links in your code.
0
 
LVL 10

Expert Comment

by:ray-solomon
ID: 36510028
Oh and you can do the same modification to the other part of the php file. This way you can have "LIKE" links for each item of the rss feed.

Change this:

  echo ("<p><a href='" . $item_link
  . "'>" . $item_title . "</a>");
  echo ("<br />");
  echo ($item_desc . "</p>");

Open in new window


to this:

  echo ("<p><a href='" . $item_link
  . "'>" . $item_title . "</a>");
  echo("<br /><a href='http://www.facebook.com/plugins/like.php?app_id=159397647477718&href=" . $item_link ."' target='_blank'>Facebook Like</a><br />");
  echo ($item_desc . "</p>");

Open in new window

0
 

Author Comment

by:spoggles
ID: 36511954
What about a re-tweet button?
0
 
LVL 10

Accepted Solution

by:
ray-solomon earned 500 total points
ID: 36513468
You can learn how to make a twitter link here:
https://dev.twitter.com/docs/tweet-button


Adding a tweet link is no problem.
I added it next to the facebook link.

//output elements from "<channel>"
echo("<p><a href='" . $channel_link . "'>" . $channel_title . "</a>");
echo("<br /><a href='http://www.facebook.com/plugins/like.php?app_id=159397647477718&href=" . $channel_link ."' target='_blank'>Facebook Like</a><br /><a href='http://twitter.com/share?url=" . $channel_link ."' target='_blank'>Tweet</a><br />");
echo($channel_desc . "</p>");

Open in new window


Also for the second part:

  echo ("<p><a href='" . $item_link
  . "'>" . $item_title . "</a>");
  echo("<br /><a href='http://www.facebook.com/plugins/like.php?app_id=159397647477718&href=" . $item_link ."' target='_blank'>Facebook Like</a><br /><a href='http://twitter.com/share?url=" . $item_link ."' target='_blank'>Tweet</a><br />");
  echo ($item_desc . "</p>");

Open in new window



0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question