Skip to content

Instantly share code, notes, and snippets.

@michaeljs1990
Created September 30, 2014 15:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michaeljs1990/0acbca3134414d882868 to your computer and use it in GitHub Desktop.
Save michaeljs1990/0acbca3134414d882868 to your computer and use it in GitHub Desktop.
People Boilerplate
<?php
/*
Template Name: UWM People Profile Directory
*/
get_header();
// Because WordPress is trying to be oh so helpful
remove_filter('the_content', 'wpautop');
// This requires you to use the /classification/$class/$tax
//set and define any taxonomies that may be applied to the archive page
$term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
//check if a taxonomy filter is present and then if it is set the values to filter by it
if(is_object($term)) { $termname = $term->name; $class = $term->slug; } else { $class = ''; }
?>
<div id="content" class="content-area">
<div id="primary" class="site-content" role="main">
<h1 class="entry-title">People Directory <?php if(is_object($term)) { echo ' - ' . $termname; } ?></h1>
<?php
wp_enqueue_style( 'uwmpeople-style' );
/*
This is a template part that is used in the archive-uwmpeople template.
This was abstracted out in order to display the same HTML using the built-in
pages, or via a shortcode that we registered.
Honestly, a lot of this are not part of views and shouldn't be in here
but alas, this is how it is.
*/
/**
* Load in the Titan Framework
* &
* Get our default options from the Titan Framework
*/
list($titan, $options) = uwmpeople_get_plugin_options();
/**
* This is used for shortcode overrides of options
* that are set globally or whatever.
*/
if ( isset( $atts ) )
{
if ( isset($atts['classification']) && $atts['classification'] != null )
{
$class = $atts['classification'];
}
if ( isset($atts['order_by']) && $atts['order_by'] != null )
{
$options['order_by'] = $atts['order_by'];
}
if ( isset($atts['order_dir']) && $atts['order_dir'] != null )
{
$options['order_dir'] = $atts['order_dir'];
}
if ( isset($atts['display_name']) && $atts['display_name'] != null )
{
$options['display_name'] = $atts['display_name'];
}
}
/**
* Construct our query for WordPress. Why do it all separately
* when we can do the logic before the query? Smart.
*/
$class = isset($class) ? $class : "";
$loop = uwmpeople_get_all_query($options, $class);
/**
* Make sure proper number of divs are added.
*/
$records_returned = $loop->post_count;
$records_per_row = 5;
$placeholder_num = $records_per_row - ($records_returned % $records_per_row);
$count = 0;
/**
* Lets go through the loop, and build the HTML structure.
*/
$records_returned = $loop->post_count;
$the_loop = '';
while ( $loop->have_posts() ) : $loop->the_post();
$count = $count + 1;
$url_to_use = get_permalink();
$the_loop .= '<div class="person">';
// By default, let's try to get the profile photo. This may return an integer
// or a URL. Thanks WordPress. If profile photo is empty, then we set it to
// default image, which ALSO might be an integer or a URL. Hopefully this covers all cases.
$featured_image = $titan->getOption('profile_photo', get_the_ID());
if ( empty($featured_image) )
$featured_image = $titan->getOption('default_image');
if ( strpos($featured_image, 'http' ) === false )
$featured_image = wp_get_attachment_url( $featured_image );
$the_loop .= '<a href="' . $url_to_use . '"><img src="' . $featured_image . '" class="attachment-post-thumbnail wp-post-image" alt="profile-photo" width="225" height="225" />';
$first_name = esc_html( $titan->getOption( 'first_name', get_the_ID() ), true );
$last_name = esc_html( $titan->getOption( 'last_name', get_the_ID() ), true );
$full_name = $last_name . ',&nbsp;' . $first_name;
if ( $options['display_name'] == 'firstlast' ) $full_name = $first_name . ' ' . $last_name;
else if ( $options['display_name'] == 'first' ) $full_name = $first_name;
$the_loop .= '<span class="person-name">' . $full_name . '</span>';
$job_title = esc_html( $titan->getOption( 'job_title', get_the_ID() ), true );
if (!empty($job_title))
$the_loop .= '<span class="person-title">' . $job_title . '</span></a>';
// Everything below this line is hidden unless overwritten.
$phone = esc_html( $titan->getOption( 'phone', get_the_ID() ), true );
if ( !empty($phone) ) $the_loop .= '<span class="uwmpeople-phone person-hidden">' . $phone . '</span>';
$email = esc_html( $titan->getOption( 'email', get_the_ID() ), true );
if ( !empty($email) ) $the_loop .= '<a class="person-hidden" href="mailto:' . $email . '">' . $email . '</a>';
$building = esc_html( $titan->getOption( 'building', get_the_ID() ), true );
$room = esc_html( $titan->getOption( 'room', get_the_ID() ), true );
if ( !empty($building) ) $the_loop .= '<span class="uwmpeople-building person-hidden">' . $building . ' ' . $room . '</span>';
$custom_fields = preg_replace("/[\r\n]+/", "\n", $titan->getOption('custom_fields'));
$split = explode(PHP_EOL, $custom_fields );
if ( is_array( $split ) && !empty( $custom_fields ) )
{
foreach ( $split as $data )
{
$field = explode( '|', $data );
$the_loop .= '<span class="person-hidden uwmpeople-' . trim($field[0]) . '">';
if ( count($field) > 1 ) // This means we defined our own in Titan
{
$the_loop .= $titan->getOption( $field[0], get_the_ID() );
}
else // This means we reach out and find one named this
{
$the_loop .= get_post_meta( get_the_ID(), trim($field[0]), true );
}
$the_loop .= '</span>';
}
}
$the_loop .= '</div> '; // End div for hidden fields and person.Removed &nbsp; and replaced with space.
endwhile;
// Add in the proper number of place holders for proper formating on resize.
if($count == $records_returned) {
for ($x=0; $x<=$placeholder_num; $x++) {
$the_loop .= '<div class="placeholder"></div>';
}
}
$the_loop = '<div class="person-container">' . $the_loop . '</div> <!-- This is the end -->';
/**
* Important! If you do not call wp_reset_query() you will cause
* other items on the page to freak out.
*/
wp_reset_query();
?>
</div>
<!-- #primary -->
</div>
<!-- #content -->
<?php get_footer(); ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment