Solved

Adding Facebook/Twitter Like Button to RSS Feed

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

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Generate PDF from MySQL using PHP 3 52
scan php uploads for viruses 5 23
Understanding ping command in Ubuntu 5 28
How do use '  ' within this code? 4 24
Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
In threads here at EE, each comment has a unique Identifier (ID). It is easy to get the full path for an ID via the right-click context menu. However, we often want to post a short link within a thread rather than the full link. This article shows a…
The viewer will learn how to count occurrences of each item in an array.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

713 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