<?php
get_header();

$album_query = new WP_Query(array(
    'post_type' => 'album',
    'posts_per_page' => -1,
    'orderby' => 'rand'
));

while ($album_query->have_posts()) {
    $album_query->the_post();

    $src = wp_get_attachment_image_src(get_post_meta(get_the_ID(), 'evrst_cover', true), 'thumbnail');
    $catalog_number = strtolower(get_post_meta(get_the_ID(), 'evrst_catalog_number', true));

    $genres = array();

    $genre_list = get_the_terms($post->ID, 'genre');

    if ($genre_list) {
        foreach ($genre_list as $genre) {
            $genres[] = $genre->name;
        }
    }


    ?>
  <div class="album-wrapper"
       data-name="<?php echo sanitize_title($post->post_title); ?>"
       data-catalog-number="<?php echo $catalog_number; ?>"
       data-genre="<?php echo join(',', $genres); ?>"
       data-tags="<?php $tags = get_the_tags(); echo is_array($tags) ? join(',', array_map('evrst_tag_name', $tags)) : ''; ?>">
    <a href="<?php the_permalink(); ?>"><img src="<?php echo $src[0]; ?>" alt="cover" /></a>
    <div class="album-content"><?php the_content(); ?></div>
  </div>
    <?php
}
wp_reset_query();

get_footer();
