ivokwee
Forum Replies Created
Viewing 3 replies - 1 through 3 (of 3 total)
-
Forum: Plugins
In reply to: [Faculty and Staff Directory] shortcode for list of one category (hack)This version can set the category name on/off (no heading).
Example:
[fsdirectory cat='admin' name='false']
<?php $a = shortcode_atts( array( 'cat' => 'all', 'exclude' => '', 'name' => 'true', ), $atts ); $cat_include = explode(",",$a['cat']); $cat_exclude = explode(",",$a['exclude']); $cat_name = ($a['name']==='true'); $custom_terms = get_terms('profile-category'); foreach($custom_terms as $custom_term) { wp_reset_query(); $args = array('post_type' => 'facstaff', 'orderby'=>'title', 'order'=>'ASC', 'posts_per_page' => -1, // Unlimited posts 'tax_query' => array( array( 'taxonomy' => 'profile-category', 'field' => 'slug', 'terms' => $custom_term->slug, ), ), ); $loop = new WP_Query($args); $cat_match = (in_array($custom_term->slug, $cat_include) || $cat_include[0]=='all'); if( $loop->have_posts() && ( $cat_match && !in_array($custom_term->slug, $cat_exclude))) { if($cat_name) echo '<h2>'.$custom_term->name.'</h2>'; while($loop->have_posts()) : $loop->the_post(); echo '<a href="'.get_permalink($facstaff_posts->ID).'">'.get_the_title().'</a><br>'; endwhile; } } ?>
Forum: Plugins
In reply to: [Faculty and Staff Directory] shortcode for list of one category (hack)Yes! This version has also an ‘exclude’ option, and accepts multiple categories.
Examples:
[fsdirectory cat='admin,students']
[fsdirectory exclude='former-members']
<?php $a = shortcode_atts( array( 'cat' => 'all', 'exclude' => '', ), $atts ); $cat_include = explode(",",$a['cat']); $cat_exclude = explode(",",$a['exclude']); $custom_terms = get_terms('profile-category'); foreach($custom_terms as $custom_term) { wp_reset_query(); $args = array('post_type' => 'facstaff', 'orderby'=>'title', 'order'=>'ASC', 'posts_per_page' => -1, // Unlimited posts 'tax_query' => array( array( 'taxonomy' => 'profile-category', 'field' => 'slug', 'terms' => $custom_term->slug, ), ), ); $loop = new WP_Query($args); $cat_match = (in_array($custom_term->slug, $cat_include) || $cat_include[0]=='all'); if( $loop->have_posts() && ( $cat_match && !in_array($custom_term->slug, $cat_exclude))) { if($cat_include[0]=='all') echo '<h2>'.$custom_term->name.'</h2>'; while($loop->have_posts()) : $loop->the_post(); echo '<a href="'.get_permalink($facstaff_posts->ID).'">'.get_the_title().'</a><br>'; endwhile; } } ?>
same problem here.
Viewing 3 replies - 1 through 3 (of 3 total)