Advertisement
Guest User

taxonomy-album.php

a guest
Dec 10th, 2015
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.65 KB | None | 0 0
  1. <?php get_header(); ?>
  2.  
  3. <div class="container clearfix">
  4.  
  5. <header class="entry-title">
  6. <h1 class = "archive-title"><ul class = "gallery_breadcrumb"><?php be_taxonomy_breadcrumb(); ?></ul></h1>
  7. </header>
  8.  
  9. <?php if (category_description( $category ) == '') : ?>
  10.  
  11. <?php else : ?>
  12.  
  13. <?php echo category_description( $category ); ?>
  14.  
  15. <?php endif; ?>
  16.  
  17. <?php
  18.  
  19. $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); // get current term
  20.  
  21. $parent = get_term($term->parent, get_query_var('taxonomy') ); // get parent term
  22.  
  23. $children = get_term_children($term->term_id, get_query_var('taxonomy')); // get children
  24.  
  25. if(($parent->term_id!="" && sizeof($children)>0)) {
  26.  
  27. $term_children = get_terms(
  28.  
  29. 'album',
  30. array(
  31.  
  32. 'parent' => get_queried_object_id(),
  33.         'order' => 'DESC',
  34.     )
  35. );
  36.  
  37. if ( ! is_wp_error( $terms ) ) {
  38.     foreach ( $term_children as $child ) {
  39.  
  40. // get one random post in this child term
  41.     $random_term_post = get_posts( array(
  42.         'posts_per_page'    => 1, // only one post
  43.         'orderby'           => 'rand', // selected randomly
  44.         'tax_query'         => array(
  45.             array(
  46.                 'taxonomy'  => 'album', // from this child album
  47.                 'terms'     => $child->term_id
  48.             )
  49.  
  50.         )
  51.  
  52.     ) );
  53.  
  54. echo '<a href="' . get_term_link( $child ) . '">
  55. <div class = "taxonomy_thumbnails">';
  56. echo get_the_post_thumbnail( $random_term_post[0], 'thumbnail' ); // show the random post's thumbnail
  57. echo '<p>' . $child->name .' </p>';
  58. echo '</div> <!-- .taxonomy_thumbnails -->';
  59. echo '</a>';
  60.     }
  61.  
  62. }
  63.  
  64. }elseif(($parent->term_id!="") && (sizeof($children)==0)) {
  65.  
  66. if ( have_posts() ) : while ( have_posts() ) : the_post();
  67.  
  68. $large_image_url = wp_get_attachment_image_src( get_post_thumbnail_id(), 'large' );
  69.  
  70. echo '<div class = "taxonomy_thumbnails">';
  71. echo '<a href="' . $large_image_url[0] . '">';
  72. echo the_post_thumbnail( 'thumbnail' );
  73. echo '</a>';
  74. echo '<p class = "artwork_info"><span style="font-weight:bold; font-style:italic;">'; echo get_the_title(); echo '</span>';
  75.  
  76. $year_as_text = strip_tags( get_the_term_list( $wp_query->post->ID, 'year-of-piece', ' &middot ', ', ', '' ) );
  77. echo $year_as_text;
  78.  
  79. echo '</p>';
  80.  
  81. $medium_as_text = strip_tags( get_the_term_list( $wp_query->post->ID, 'medium', '', ', ', '' ) );
  82. echo $medium_as_text;
  83.  
  84. $size_as_text = strip_tags( get_the_term_list( $wp_query->post->ID, 'size', ' &middot ', ', ', '' ) );
  85. echo $size_as_text;
  86.  
  87. echo '</div><!-- .taxonomy_thumbnails -->';
  88.  
  89. endwhile; else : ?>
  90.     <p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
  91. <?php endif; ?>
  92.  
  93. <?php
  94.  
  95. }elseif(($parent->term_id=="") && (sizeof($children)>0)) {
  96.  
  97. $term_children = get_terms(
  98.     'album',
  99.     array(
  100.         'parent' => get_queried_object_id(),
  101.  
  102.         'order' => 'DESC',
  103.     )
  104.  
  105. );
  106.  
  107. if ( ! is_wp_error( $terms ) ) {
  108.     foreach ( $term_children as $child ) {
  109.  
  110. // get one random post in this child term
  111. $random_term_post = get_posts( array(
  112.   'posts_per_page'    => 1, // only one post
  113.         'orderby'           => 'rand', // randomly selected
  114.         'tax_query'         => array(
  115.             array(
  116.                 'taxonomy'  => 'album', // from this child album
  117.                 'terms'     => $child->term_id
  118.             )
  119.         )
  120.  
  121.     ) );
  122.  
  123. echo '<a href="' . get_term_link( $child ) . '">
  124. <div class = "taxonomy_thumbnails">';
  125. echo get_the_post_thumbnail( $random_term_post[0], 'thumbnail' ); // show the random post's thumbnail
  126. echo '<p>' . $child->name .' </p>';
  127. echo '</div> <!-- .taxonomy_thumbnails -->';
  128. echo '</a>';
  129.     }
  130.  
  131. }
  132.  
  133. }
  134.  
  135. ?>
  136. </div> <!-- end of container -->
  137. <?php get_footer(); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement