Solved

Adding Facebook/Twitter Like Button to RSS Feed

Posted on 2011-09-02
4
2,159 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

863 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now