Last active
December 15, 2015 03:19
-
-
Save dougedgington/5193797 to your computer and use it in GitHub Desktop.
Output custom post type in a grid via shortcode in WordPress.
This file contains hidden or 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 | |
/* | |
Author: Doug Edgington | |
Description: Shortcode to output custom post type in a grid | |
*/ | |
function dee_display_bios() { | |
$args = array( | |
'post_type' => 'dee_bios', | |
'orderby' => 'title', | |
'order' => 'ASC', | |
'posts_per_page'=> -1, | |
); | |
$dee_bios = new WP_Query( $args ); | |
if( $dee_bios->have_posts() ): | |
$dee_output = '<div id="bios">'; | |
while ( $dee_bios->have_posts() ) : $dee_bios->the_post(); | |
if( $dee_bios->current_post == 0 || ( $dee_bios->current_post % 2 ) == 0 ) { | |
$dee_output .= '<div class="one-half first">'; | |
} | |
else { | |
$dee_output .= '<div class="one-half">'; | |
} | |
$dee_output .= get_the_post_thumbnail( $dee_bios->post->ID, 'bios', array( 'class' => 'alignleft' ) ); | |
$dee_output .= '<p><strong>' . get_the_title() . ',</strong> ' . get_the_content() . '</p>'; | |
$dee_output .= '</div><!--end .one-half-->'; | |
endwhile; | |
$dee_output .= '<div class="clear"></div><!--clear all floats-->'; | |
$dee_output .= '</div><!-- end #bios-->'; | |
endif; | |
wp_reset_postdata(); | |
return $dee_output; | |
} | |
add_shortcode( 'dee-bios', 'dee_display_bios' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment