Obtain data from JSON
-
hi I would like to obtain data from JSON (e.g: the title & thumbnail) instead of displaying title from default post title.
here’s my code (template-parts) for home page:
<?php $id = get_post_meta( get_the_ID(), 'itunes_id', true ); $country = get_post_meta( get_the_ID(), 'select_country', true ); $json = file_get_contents("https://itunes.apple.com/$country/lookup?id=$id&entity=song"); $data = json_decode($json); foreach ($data->results as $row){ $aw = $row->artworkUrl100; ?> <a class="hidden-last-child" href="<?php the_permalink() ?>"> <div class="store-product"> <figure> <img src="<?php echo str_replace("100x100bb","313x0w","$aw"); ?>" alt="<?php echo $row->artistName . ' - ' . $row->collectionName; ?>"> </figure> <div class="music-title"> <h2 class="album-title"> <?php if ( in_category( 4 ) || in_category( 6 ) ) { echo $row->trackName; } else { echo $row->collectionName; } ?> </h2> <h3 class="artis-title"><?php echo $row->artistName; ?></h3> </div> </div> </a> <?php break; } ?>
How can I resolve this?
The page I need help with: [log in to see the link]
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
- The topic ‘Obtain data from JSON’ is closed to new replies.