Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. add_shortcode('data-display', 'custom_api_data_display');
  2. function custom_api_data_display($atts) {
  3.  
  4. // for whatever you API call function is
  5. // you may want check $_REQUEST or shortcode $atts to modify
  6. $args = array('some_key' => 'some_value', 'some_key2' => 'some_value2');
  7. $data = custom_api_data_request($args);
  8.  
  9. if (count($data) > 0) {
  10. $html = '<div class="result-container">';
  11. foreach ($data as $result) {
  12. $html .= '<div class="single-result">';
  13.  
  14. // output whatever data result keys you like here
  15. // this is just a simple example with image, title and description
  16. $html .= '<img class="result-image" src="'.$result['image_url'].'">';
  17. $html .= '<div class="result-title">'.$result['title'].'</div>';
  18. $html .= '<div class="result-description">'.$result['description'].'</div>';
  19.  
  20. $html .= '</div>';
  21. }
  22. $html .= '</div>';
  23. } else {
  24. $html = '<p>No results found.</p>';
  25. }
  26.  
  27. return $html;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement