Solved

Adding Facebook/Twitter Like Button to RSS Feed

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
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 …

744 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

11 Experts available now in Live!

Get 1:1 Help Now