Advertisement
Imperative-Ideas

A taxonomy images loop for S8

May 27th, 2014
421
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.99 KB | None | 0 0
  1. <?php
  2.  
  3. // A function that returns all staff members in an unordered list
  4. function mod_get_staff($scope, $size) {
  5.     if ('all' == $scope) :
  6.         $the_terms = get_terms('people'); // get all of the terms in the people taxonomy
  7.     elseif ( 'post' == $scope ) : // get only the terms connected to this post
  8.         global $post;
  9.         $the_terms = get_the_terms($post->ID, 'people');
  10.     else :
  11.         return;
  12.     endif;
  13.  
  14.     $fakeuser = array( // this is an array of images for use when no image exists
  15.         'mystery_1' => get_bloginfo('stylesheet_directory') . "/library/images/mysteryman/user-1.png",
  16.         'mystery_2' => get_bloginfo('stylesheet_directory') . "/library/images/mysteryman/user-2.png",
  17.         'mystery_3' => get_bloginfo('stylesheet_directory') . "/library/images/mysteryman/user-3.png"
  18.     );
  19.  
  20.     $output =  "<ul class='team-bios'>";
  21.     foreach ($the_terms as $key => $value) { // for each term, execute the following loop
  22.         $thesize = $size; // use the thumbnail image, if available
  23.         $image_obj = s8_get_taxonomy_image_src($the_terms[$key], $thesize); // Grab the taxonomy image object
  24.  
  25.         if ( !empty($image_obj)) : // check if the image object is empty
  26.             $image_src = $image_obj['src']; // grab the URL of the taxonomy image for this term
  27.         else :
  28.             $image_src = $fakeuser[array_rand($fakeuser)]; // if no image is available, use a the placeholder array
  29.         endif;
  30.  
  31.         $output .=  "<li>";
  32.         $output .=  "<img class='modiodojo' src='$image_src' alt='$value->name | $value->description' /><br />";
  33.         $output .=  "<div class='imageover'>"; // CSS overlay containing the taxonomy information
  34.         $output .=  "<h3>$value->name</h3>"; // This is the name of the taxonomy
  35.         $output .=  "<p>$value->description</p>"; // We use the description as the person's title in this example
  36.         $output .=  "</div>";
  37.         $output .=  "</li>";
  38.     }
  39.     $output .=  "</ul>";
  40.  
  41.     echo $output;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement