Advertisement
cgrymala

Custom taxonomy archive

Jul 30th, 2012
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.11 KB | None | 0 0
  1.     /**
  2.      * Ensures all queries pull posts in ascending alpha order.
  3.      * Called by using the pre_get_posts action within the __construct() method of this class
  4.      */
  5.     function alpha_posts( $query ) {
  6.         set_query_var( 'orderby', 'title' );
  7.         set_query_var( 'order', 'ASC' );
  8.     }
  9.    
  10.     /**
  11.      * Run the custom loop for archive pages
  12.      * @uses do_action() to run the sau-contact-start-archive-loop and
  13.      *      sau-contact-done-archive-loop actions to allow output before/after
  14.      *      the loop
  15.      */
  16.     function archive_loop() {
  17.         $obj = get_queried_object();
  18.         if ( is_object( $obj ) ) {
  19.             /*if ( property_exists( $obj, 'taxonomy' ) ) {
  20.                 $tmp = get_taxonomy( $obj->taxonomy );
  21.                 printf( '<h1>%s</h1>', $tmp->labels->name );
  22.             }*/
  23.             if ( property_exists( $obj, 'name' ) )
  24.                 printf( '<h1 class="%2$s">%1$s</h1>', $obj->name, apply_filters( 'sau-contact-archive-title-class', 'archive-title' ) );
  25.         }
  26.        
  27.         $i = 0;
  28.         global $post;
  29.         do_action( 'sau-contact-start-archive-loop' );
  30.         if ( have_posts() ) :
  31.             while ( have_posts() ) : the_post();
  32.                 error_log( '[SAU Debug]: ' . $post->post_name );
  33.                 $this->do_archive_entry( $post, $i );
  34.                 $i++;
  35.             endwhile;
  36.         else :
  37.             _e( apply_filters( 'sau-contact-no-posts', '<p>Sorry, no posts matched your criteria.</p>' ) );
  38.         endif;
  39.         do_action( 'sau-contact-done-archive-loop' );
  40.     }
  41.    
  42.     /**
  43.      * Output the actual content for an entry on an archive page
  44.      * @param stdClass $post the WordPress post object
  45.      * @param int $i a counter for determining which class to assign
  46.      */
  47.     function do_archive_entry( $post = null, $i = 0 ) {
  48.         echo $this->get_archive_entry( $post, $i );
  49.     }
  50.    
  51.     function get_archive_entry( $post = null, $i = 0 ) {
  52.         if ( empty( $post ) )
  53.             global $post;
  54.        
  55.         setup_postdata( $post );
  56.        
  57.         $title = apply_filters( 'title-wpcm-value', get_post_meta( $post->ID, 'title_wpcm_value', true ) );
  58.        
  59.         $names = array();
  60.         $names[] = get_post_meta( get_the_ID(), 'first_name_wpcm_value', true );
  61.         $names[] = get_post_meta( get_the_ID(), 'last_name_wpcm_value', true );
  62.         $names = apply_filters( 'name-wpcm-value', implode( ' ', $names ), $names );
  63.        
  64.         $has_email = is_email( apply_filters( 'email-wpcm-value', get_post_meta( get_the_ID(), 'email_wpcm_value', true ) ) );
  65.        
  66.         $phone = apply_filters( 'phone-wpcm-value', get_post_meta( get_the_ID(), 'office_phone_wpcm_value', true ) );
  67.        
  68.         $d = get_the_terms( get_the_ID(), 'department' );
  69.         $depts = array();
  70.         foreach ( $d as $t ) {
  71.             $depts[] = $t->name;
  72.         }
  73.         $depts = '<span class="departments" style="font-style: italic; display: block">' . implode( ', ', $depts ) . '</span>';
  74.        
  75.         return apply_filters( 'sau-contact-archive-entry', '
  76.     <div class="contact' . ( $i % 2 ? ' alt' : '' ) . '">
  77.         <span class="m-name"><a href="' . get_permalink() . '" title="' . esc_attr( $title ) . '">' . $names . '</a></span>
  78.         <span class="m-email">' . ( $has_email ? '<a href="mailto:' . $has_email . '">' . $has_email . '</a>' : '&nbsp;' ) . '</span>
  79.         <span class="m-mobile"><span>870-235-' . $phone . '</span> (O)</span>
  80.         <span class="title">' . $title . '</span>
  81.         ' . $depts . '
  82.     </div>' );
  83.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement