my_twitter_feed_template_tag

The DevBuddy Twitter Feed Plugin my twitter feed template tag function.

Description

my_twitter_feed_template_tag( (null) $feed_config = null ); 

Parameters (1)

0. $feed_config — Optional. (null) => null
The feed config.

Usage

  1. if ( !function_exists( 'my_twitter_feed_template_tag' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'devbuddy-twitter-feed-plugin/assets/sample-template-tag.php'; 
  3.  
  4. // The feed config. 
  5. $feed_config = null; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = my_twitter_feed_template_tag($feed_config); 
  9.  

Defined (1)

The function is defined in the following location(s).

/assets/sample-template-tag.php  
  1. function my_twitter_feed_template_tag( $feed_config = NULL ) { 
  2.  
  3. // Configuration validity checks are performed on instantiation 
  4. $the_feed = new DB_Twitter_Feed( $feed_config ); 
  5.  
  6.  
  7. // We only want to talk to Twitter when our cache is on empty 
  8. if ( ! $the_feed->is_cached ) { 
  9.  
  10. // Makes a request to Twitter for tweet data based on $the_feed->options 
  11. $the_feed->retrieve_feed_data(); 
  12.  
  13.  
  14. // After attempting data retrieval, check for errors 
  15. // Feel free to change theerrormessage 
  16. if ( $the_feed->has_errors() ) { 
  17. $the_feed->output .= '<p>We’re unable to show tweets at this time.</p>'; 
  18.  
  19. // Uncomment the following code to see the details of errors 
  20. /** 
  21. $the_feed->output .= '<ul>'; 
  22.   
  23. foreach ( $the_feed->errors as $error ) { 
  24. $the_feed->output .= '<li>“'.$error->message.' [error code: '.$error->code.']”</li>'; 
  25.   
  26. $the_feed->output .= '</ul>'; 
  27. $the_feed->output .= '<p>More information on errors <a href="https://dev.twitter.com/docs/error-codes-responses" target="_blank" title="Twitter API Error Codes and Responses">here</a>.</p>'; 
  28. */ 
  29.  
  30.  
  31. // Then check for an empty timeline 
  32. // Feel free to change the notification message 
  33. } elseif( $the_feed->is_empty() ) { 
  34. $the_feed->output .= '<p>Looks like this feed is completely empty! Perhaps try a different user or search term.</p>'; 
  35.  
  36.  
  37. // If all is well we can get to HTML renderin' 
  38. } else { 
  39.  
  40. // START The Tweet list 
  41. $the_feed->output .= '<div class="tweets">'; 
  42.  
  43. foreach ( $the_feed->feed_data as $tweet ) { 
  44.  
  45. /** Parse the tweet data and hand that data over to the HTML 
  46. class which will write the HTML code for us */ 
  47. $the_feed->html->set( $the_feed->parse_tweet_data( $tweet ) ); 
  48.  
  49.  
  50. /** Below is the default HTML layout. 
  51.   
  52. The HTML class writes the actual HTML, just move the 
  53. parts around as needed. 
  54.   
  55. If you do move things around, be sure to update your 
  56. stylesheet accordingly. 
  57.   
  58. NOTE: The primary and secondary meta HTML parts are 
  59. merely generic div elements used as content wrappers. 
  60. *********************************************************/ 
  61.  
  62. // START Rendering the Tweet's HTML (outer tweet wrapper) 
  63. $the_feed->output .= $the_feed->html->open_tweet(); 
  64.  
  65.  
  66. // START Tweet content (inner tweet wrapper) 
  67. $the_feed->output .= $the_feed->html->open_tweet_content(); 
  68.  
  69.  
  70. // START Tweeter's display picture 
  71. $the_feed->output .= $the_feed->html->tweet_display_pic(); 
  72. // END Tweeter's display picture 
  73.  
  74.  
  75. // START Tweet user info 
  76. $the_feed->output .= $the_feed->html->open_tweet_primary_meta(); 
  77. $the_feed->output .= $the_feed->html->tweet_display_name_link(); 
  78. $the_feed->output .= $the_feed->html->close_tweet_primary_meta(); 
  79. // END Tweet user info 
  80.  
  81.  
  82. // START Actual tweet 
  83. $the_feed->output .= $the_feed->html->tweet_text(); 
  84. $the_feed->output .= $the_feed->html->tweet_media(); 
  85. // END Actual tweet 
  86.  
  87.  
  88. // START Tweet meta data 
  89. $the_feed->output .= $the_feed->html->open_tweet_secondary_meta(); 
  90. $the_feed->output .= $the_feed->html->tweet_date(); 
  91. $the_feed->output .= $the_feed->html->tweet_retweeted(); 
  92. $the_feed->output .= $the_feed->html->tweet_intents(); 
  93. $the_feed->output .= $the_feed->html->close_tweet_secondary_meta(); 
  94. // END Tweet meta data 
  95.  
  96.  
  97. $the_feed->output .= $the_feed->html->close_tweet_content(); 
  98. // END Tweet content 
  99.  
  100.  
  101. $the_feed->output .= $the_feed->html->close_tweet(); 
  102. // END Rendering Tweet's HTML 
  103.  
  104. } // END looping through tweet data 
  105.  
  106. $the_feed->output .= '</div>'; 
  107. // END The Tweet list 
  108.  
  109. // Cache the output 
  110. $the_feed->cache_output( $the_feed->options['cache_hours'] ); 
  111.  
  112.  
  113. } // END cache check 
  114.  
  115.  
  116. /** WP needs shortcode called content to be returned 
  117. rather than echoed, which is where the 
  118. $is_shortcode_called property comes in */ 
  119. if ( $the_feed->is_shortcode_called ) { 
  120. return $the_feed->output; 
  121. } else { 
  122. echo $the_feed->output; 
  123.