Support » Plugin: Simple Staff List » Staff index to use as anchor links

  • Resolved brpubs

    (@brpubs)


    Hi —

    Ran into two issues that I decided to address through a new function rather than trying to modify SSLP. The first was that I wanted a staff index at the top of the staff listing page that would provide links to individual staff members, since it’s a long list with relatively long bios. The second was that I wanted that index to include names only, without the professional degrees that I included in the name field (after concluding it would take too much time to add a separate field for those).

    Posting it below in case it’s of use to anyone. It’s basically an adaptation of SSPL’s user-view-show-staff-list.php. I’m not an advanced php writer, so there may be a more elegant way to do this — but it works. It assumes that an anchor using the staff-name-slug has been included in the SSPL default template.

    I assume I could also have done this using the multiple template approach someone else offered, but this seemed a bit simpler for my needs. Eager to hear if I totally overlooked a simpler method that already existed…

    function get_staff_index($atts)
    {
    
        // Initialize variables
        $group = '';
        $order = '';
    
        extract(shortcode_atts(array(
            'single' => 'no',
            'group' => '',
            'wrap_class' => '',
            'order' => 'ASC',
        ), $atts));
    
        // Get data outside of sslp template
        $default_tags = get_option('_staff_listing_default_tags');
        $default_formatted_tags = get_option('_staff_listing_default_formatted_tags');
        $output = '';
        $group = strtolower($group);
        $group_class = str_replace(' ', '-', $group); //added to avoid spaces in class
        $order = strtoupper($order);
        $staff = '';
    
        /**
         * Set up our WP_Query
         */
    
        $args = array('post_type' => 'staff-member', 'posts_per_page' => -1, 'orderby' => 'menu_order', 'post_status' => 'publish');
    
        // Check user's 'order' value
        if ($order != 'ASC' && $order != 'DESC') {
            $order = 'ASC';
        }
    
        // Set 'order' in our query args
        $args['order'] = $order;
    
        // Check user's 'group' value
        $group_terms = get_sslp_terms('staff-member-group');
        if (in_array($group, $group_terms)) {
            // if it's an actual term, set it in query args
            $args['staff-member-group'] = $group;
        }
    
        $staff = new WP_Query($args);
    
        // Set up loop and format output
        $i = 0;
        if ($staff->have_posts()) {
            $output .= '<div class="staff-member-index ' . $group_class . '">';
    
            while ($staff->have_posts()) : $staff->the_post();
                $staff_index_classes = '';
                if ($i == ($staff->found_posts) - 1) {
                    $staff_index_classes .= " last";
                }
                global $post;
                $custom = get_post_custom();
                $name = get_the_title();
                $nameparts = explode(",", $name); //break the name and professional degrees into two strings
                $barename = $nameparts['0']; //return only the name
                $name_slug = basename(get_permalink());
    
                $output .= '<a href="#' . $name_slug . '" class="' . $staff_index_classes . '">' . $barename . '</a>';
                $i += 1;
            endwhile;
    
            $output .= "</div> <!-- Close staff-member-listing -->";
        }
        return $output;
    }
    
    add_shortcode('simple-staff-index', 'get_staff_index');

    http://wordpress.org/extend/plugins/simple-staff-list/

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Staff index to use as anchor links’ is closed to new replies.