Created
September 8, 2010 20:25
-
-
Save markjaquith/570774 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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' ); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@markjaquith What's the reason for restoring globals when WP_Query is in use which doesn't touch globals?