Solved

Adding Facebook/Twitter Like Button to RSS Feed

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

Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

828 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