Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_shortcode('data-display', 'custom_api_data_display');
- function custom_api_data_display($atts) {
- // for whatever you API call function is
- // you may want check $_REQUEST or shortcode $atts to modify
- $args = array('some_key' => 'some_value', 'some_key2' => 'some_value2');
- $data = custom_api_data_request($args);
- if (count($data) > 0) {
- $html = '<div class="result-container">';
- foreach ($data as $result) {
- $html .= '<div class="single-result">';
- // output whatever data result keys you like here
- // this is just a simple example with image, title and description
- $html .= '<img class="result-image" src="'.$result['image_url'].'">';
- $html .= '<div class="result-title">'.$result['title'].'</div>';
- $html .= '<div class="result-description">'.$result['description'].'</div>';
- $html .= '</div>';
- }
- $html .= '</div>';
- } else {
- $html = '<p>No results found.</p>';
- }
- return $html;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement