Skip to content

Instantly share code, notes, and snippets.

@markjaquith
Created September 8, 2010 20:25
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save markjaquith/570774 to your computer and use it in GitHub Desktop.
Save markjaquith/570774 to your computer and use it in GitHub Desktop.
<?php
/*
Plugin Name: Employee List
Description: Leverages an existing "employee" custom post type to create a shortcode for a list of employees
Version: 0.1
Author: Mark Jaquith
Author URI: http://coveredwebservices.com/
*/
function tampa_employee_list() {
global $post;
$old_globals = $GLOBALS;
$employees = new WP_Query(
array(
'post_type' => 'employee',
'posts_per_page' => 50,
'orderby' => 'post_title',
'order' => 'ASC'
)
);
$return = '';
while ( $employees->have_posts() ): $employees->the_post();
$return .= "<div class='employee'>";
$return .= get_the_post_thumbnail( $post->ID, 'thumbnail' );
$return .= "<p><strong>";
$return .= get_the_title();
$return .= "</strong><br />";
if ( !empty( $post->post_excerpt ) )
$return .= "<em>" . $post->post_excerpt . "</em>";
$return .= "</p>";
$return .= "</em></p>";
$return .= get_the_content();
$return .= "</div>";
endwhile;
$GLOBALS = $old_globals;
return $return;
}
function tampa_css_hack() {
?>
<style>
div.employee { clear: both; margin: 20px auto; float: left; }
div.employee img { float: left; padding-right: 15px; }
</style>
<?php
}
function tampa_init() {
add_shortcode( 'employees', 'tampa_employee_list' );
}
add_action( 'init', 'tampa_init' );
add_action( 'wp_head', 'tampa_css_hack' );
@ashfame
Copy link

ashfame commented Jan 24, 2014

@markjaquith What's the reason for restoring globals when WP_Query is in use which doesn't touch globals?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment