-
Notifications
You must be signed in to change notification settings - Fork 7
/
page-lastfm.php
executable file
·55 lines (45 loc) · 1.41 KB
/
page-lastfm.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
/**
* Template Name: Last.fm
*/
get_header(); ?>
<div>
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'content', 'page' ); ?>
<?php endwhile; // end of the loop. ?>
<?php
$username = $options['lastfm_username'];
$scrobbler_url = "http://ws.audioscrobbler.com/2.0/user/" . $username . "/recenttracks";
if ($scrobbler_xml = file_get_contents($scrobbler_url)):
$scrobbler_data = simplexml_load_string($scrobbler_xml);
?>
<div class="center-content">
<ul class="last-fm-tracks ">
<?php foreach ($scrobbler_data->track as $track): ?>
<li>
<span class="track-date">
<?php if ($track->date): ?>
Played on <?php echo $track->date ?>
<?php else: ?>
<i>Playing now...</i>
<?php endif ?>
</span>
<span class="track-album">
<?php if (!empty($track->image[2])): ?>
<img class="cover" src="<?php echo $track->image[2] ?>" />
<?php else: ?>
<i class="cover">No Image</i>
<?php endif ?>
</span>
<div class="track">
<span class="track-name"><?php echo $track->name ?></span>
<span class="space">–</span>
<span class="track-artist"><?php echo $track->artist ?></span>
</div>
</li>
<?php endforeach ?>
</ul>
</div>
<?php endif; ?>
</div>
<?php get_footer() ?>