WPIntell

Source evidence

shortcode for list of one category (hack)

Faculty and Staff Directory · support · 2016-02-05T00:18:00+00:00

complaintsentiment
highseverity
0.96relevance
2replies
Evidence linked to opportunitycommercial context

Proof Health

Open evidence

Commercial opportunities need traceable source links before they are treated as build-worthy.

5 / 31 rows with source links

16.1% of this page's analysis has direct source links.

0 build-decision rows missing links

0 rows here require auditable proof before promotion.

26 rows with no attached evidence

0 rows have source counts but still need direct links.

Conversation

support
ivokwee unresolved
Hi. I managed to hack the template file “facstaff-category-template.php” to list a single category with a shortcode option. Just replace the file in the folder ‘display-templates’. Use it for example like [fsdirectory cat='admin'] Ivo —————— <?php $a = shortcode_atts( array('cat' => 'all',), $atts ); $my_category = $a['cat']; $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); if($loop->have_posts() && ($custom_term->slug==$my_category || $my_category=='all')) { if($my_category=='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; } } https://wordpress.org/plugins/faculty-and-staff-directory/ 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; } } ?> 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; } } ?>

Comments

2 shown
ivokwee 2016-02-05T01:00:00+00:00

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; } } ?>

ivokwee 2016-02-05T01:34:00+00:00

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; } } ?>