{"id":96,"date":"2010-06-23T23:15:27","date_gmt":"2010-06-23T23:15:27","guid":{"rendered":"http:\/\/soliloquyforthefallen.net\/blog\/?p=96"},"modified":"2015-03-05T07:18:45","modified_gmt":"2015-03-05T07:18:45","slug":"twitter-feed-on-homepage-code","status":"publish","type":"post","link":"https:\/\/soliloquyforthefallen.net\/?p=96","title":{"rendered":"Twitter Feed on HomePage Code"},"content":{"rendered":"<p>On my homepage, you may notice that I have a bit of code to get my latest tweet for this website&#8217;s twitter account.  Usually this is blog updates, but it may show other things.<\/p>\n<p>I originally found this code on <a href=\"http:\/\/www.phoenixheart.net\/2009\/05\/code-snippet-1-get-latest-tweet\/\">http:\/\/www.phoenixheart.net\/2009\/05\/code-snippet-1-get-latest-tweet\/<\/a>.  Since twitter has been having issues lately, I realized a need for a fall back value if the code couldn&#8217;t get anything.  I also removed a variable declaration and then copied the returned value from the function to another variable, to hopefully optimize the code and make it work better and faster.<\/p>\n<pre>&lt;?php\n\n \/\/ the function\n \/**\n * @desc Get latest tweet from a Twitter account\n * @param string The account's username\n * @return string The tweet\n * http:\/\/www.phoenixheart.net\/2009\/05\/code-snippet-1-get-latest-tweet\/\n *\n *\/\n function get_latest_tweet($username) {\n $url = \"http:\/\/search.twitter.com\/search.atom?q=from:$username&amp;rpp=1\";\n $content = file_get_contents($url);\n $content = explode('&lt;content type=\"html\"&gt;', $content);\n $content = explode('&lt;\/content&gt;', $content[1]);\n return html_entity_decode($content[0]);\n }\n $my_tweet = get_latest_tweet('TWITTERLOGIN');\n if ($my_tweet == NULL)\n {\necho \"Twitter is having issues again . . . .\";\n }\n else {\n echo \"$my_tweet\";\n }\n\n ?&gt;\n<\/pre>\n<p>Just paste this in a php file and change your twitter name so it gets the right feeds!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>On my homepage, you may notice that I have a bit of code to get my latest tweet for this website&#8217;s twitter account. Usually this is blog updates, but it may show other things. I originally found this code on http:\/\/www.phoenixheart.net\/2009\/05\/code-snippet-1-get-latest-tweet\/. Since twitter has been having issues lately, I realized a need for a fall&#8230; <\/p>\n<div class=\"read-more navbutton\"><a href=\"https:\/\/soliloquyforthefallen.net\/?p=96\">Read More<i class=\"fa fa-angle-double-right\"><\/i><\/a><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[117],"tags":[],"_links":{"self":[{"href":"https:\/\/soliloquyforthefallen.net\/index.php?rest_route=\/wp\/v2\/posts\/96"}],"collection":[{"href":"https:\/\/soliloquyforthefallen.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/soliloquyforthefallen.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/soliloquyforthefallen.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/soliloquyforthefallen.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=96"}],"version-history":[{"count":1,"href":"https:\/\/soliloquyforthefallen.net\/index.php?rest_route=\/wp\/v2\/posts\/96\/revisions"}],"predecessor-version":[{"id":770,"href":"https:\/\/soliloquyforthefallen.net\/index.php?rest_route=\/wp\/v2\/posts\/96\/revisions\/770"}],"wp:attachment":[{"href":"https:\/\/soliloquyforthefallen.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=96"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/soliloquyforthefallen.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=96"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/soliloquyforthefallen.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=96"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}