Created
January 22, 2013 16:23
-
-
Save dcatkins40/4596007 to your computer and use it in GitHub Desktop.
Example of using an PHP to access JSON if jQuery fails.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| $response = wp_remote_get( '$API_URL' ); | |
| if( is_wp_error( $response ) ) { | |
| echo 'Something went wrong!'; | |
| } else { | |
| echo 'Response:<pre>'; | |
| print_r( $response ); | |
| echo '</pre>'; | |
| } | |
| $decodedResponse = json_decode($response['body']); | |
| $items = $decodedResponse->items; | |
| <?php | |
| foreach($items as $item) { | |
| if($item->id == $videoID) { ?> | |
| <img src="<?php echo $item->videoStillURL; ?>" /> | |
| <?php break; | |
| } | |
| } ?> | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment