Created
July 13, 2013 17:27
-
-
Save alexkingorg/5991434 to your computer and use it in GitHub Desktop.
Shortcode to output projects by group.
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 | |
function akv3_project_group_shortcode($atts) { | |
extract(shortcode_atts(array( | |
'group' => null, | |
'description' => null, | |
), $atts)); | |
if (empty($group)) { | |
return ''; | |
} | |
$term = get_term_by('slug', $group, 'project-groups'); | |
?> | |
<h2 class="widget-title clearfix"><?php echo esc_html($term->name); ?></h2> | |
<div class="project-group clearfix"> | |
<?php | |
if (!empty($description)) { | |
echo wpautop(wptexturize($description)); | |
} | |
$args = array( | |
'post_type' => 'project', | |
'posts_per_page' => -1, | |
'orderby' => 'title', | |
'order' => 'ASC', | |
'tax_query' => array( | |
array( | |
'taxonomy' => 'project-groups', | |
'field' => 'slug', | |
'terms' => $group, | |
) | |
) | |
); | |
if ($group != 'featured') { | |
$args['tax_query'][] = array( | |
'taxonomy' => 'project-groups', | |
'field' => 'slug', | |
'terms' => 'featured', | |
'operator' => 'NOT IN' | |
); | |
} | |
$query = new WP_Query($args); | |
while ($query->have_posts()) { | |
$query->the_post(); | |
// AKV#_PATH is defined in my child theme | |
include(AKV3_PATH.'misc/project-summary.php'); | |
} | |
?> | |
</div> | |
<?php | |
wp_reset_postdata(); | |
} | |
add_shortcode('project-group', 'akv3_project_group_shortcode'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment