/ds-gallery-masonry-template.php

https://github.com/endter/Touchfolio · PHP · 66 lines · 56 code · 0 blank · 10 comment · 7 complexity · fd8bcce8c6b4641420fa6e1aca5cc245 MD5 · raw file

  1. <?php
  2. /**
  3. *
  4. * Template Name: Masonry Gallery Page
  5. *
  6. * The template for displaying gallery page with masonry layout.
  7. *
  8. * @package dsframework
  9. * @since dsframework 1.0
  10. *
  11. */
  12. ?>
  13. <?php get_header(); ?>
  14. <div id="primary" class="site-content">
  15. <div id="content" role="main">
  16. <?php
  17. $gallery_cats = get_ds_option('album_cats_gallery_page');
  18. if($gallery_cats) {
  19. $tax_query = array(
  20. 'relation' => 'AND',
  21. array(
  22. 'taxonomy' => 'ds-gallery-category',
  23. 'field' => 'slug',
  24. 'terms' => preg_split("/\s*,\s*/", $gallery_cats),
  25. 'include_children' => true,
  26. 'operator' => 'IN'
  27. )
  28. );
  29. } else {
  30. $tax_query = '';
  31. }
  32. $loop = new WP_Query( array(
  33. 'post_type' => 'ds-gallery',
  34. 'posts_per_page' => -1,
  35. 'tax_query' => $tax_query
  36. ));
  37. ?>
  38. <section class="albums-thumbnails clearfix">
  39. <?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
  40. <a class="project-thumb" href="<?php the_permalink(); ?>" data-album-id="<?php echo $post->post_name; ?>">
  41. <div class="project-thumb-inside">
  42. <?php
  43. if ( has_post_thumbnail($post->ID) ) {
  44. the_post_thumbnail( 'gallery-thumb' );
  45. } else {
  46. $post_meta = get_post_custom();
  47. $post_meta = unserialize( $post_meta['dsframework-gallery'][0] );
  48. if( isset( $post_meta['attachment_urls'] ) ) {
  49. $image_urls = $post_meta['attachment_ids'];
  50. echo wp_get_attachment_image( $image_urls[0], 'gallery-thumb' );
  51. } else {
  52. echo '<div style="width: 360px; height: 250px; background: grey;">' . __('Album images not found.', 'dsframework') . '</div>';
  53. }
  54. }
  55. ?>
  56. <h4 class="project-title"><?php the_title(); ?></h4>
  57. <p class="project-description"><?php echo get_the_excerpt(); ?></p>
  58. </div>
  59. </a>
  60. <?php endwhile; ?>
  61. </section>
  62. <?php wp_reset_postdata(); ?>
  63. </div>
  64. </div>
  65. <?php get_sidebar(); ?>
  66. <?php get_footer(); ?>