WordPress.org

Ready to get started?Download WordPress

Forums

List Related Staff using Simple Staff List Plugin (1 post)

  1. skyoyugi
    Member
    Posted 1 year ago #

    I must be thankful for this great plugin. It has saved me lots of work.

    Recently, I wanted to add a list of related staff to my website, http://ueab.ac.ke/baraton

    I took the following steps:
    1. Created a single post template called single-staff-member.php
    2. Inserted all the custom fields into the template
    3. Tried YARPP, but it did not work for me: http://wordpress.org/plugins/yet-another-related-posts-plugin/
    4. Inserted the code below, a modification I had gotten in wordpress forums like this one:

    <?php
    $custom = get_post_custom();
    $name = get_the_title();
    $name_slug = basename(get_permalink());
    $title = $custom["_staff_member_title"][0];
    $email = $custom["_staff_member_email"][0];
    $phone = $custom["_staff_member_phone"][0];
    $bio    = $custom["_staff_member_bio"][0];
    if(has_post_thumbnail()){
            $photo_url = wp_get_attachment_url( get_post_thumbnail_id() );
            $photo = '<img class="staff-member-photo" src="'.$photo_url.'" alt = "'.$title.'">';
    }
    echo '<div>';
    echo $photo;
    echo '<b>Name:</b> '.$name.'';
    echo '<b>Email:</b> '.$email.'';
    echo '<b>Phone:</b> '.$phone.'';
    the_terms( $post->ID, 'staff-member-group', 'Belongs to: ', ', ', ' Department' );
    echo '</div>';   ?>
    <?php //* RELATED STAFF MEMBERS  ?>
    <?php
    		//for in the loop, display all "content", regardless of post_type,
    		//that have the same custom taxonomy (e.g. genre) terms as the current post
    		$found_none = '<h2>No related posts found!</h2>';
    		$taxonomy = 'staff-member-group';//  e.g. post_tag, category, custom taxonomy
    		$param_type = 'staff-member-group'; //  e.g. tag__in, category__in, but genre__in will NOT work
    		$tax_args=array('orderby' => 'rand');
    		$tags = wp_get_post_terms( $post->ID , $taxonomy, $tax_args);
    			if ($tags) {
    				foreach ($tags as $tag) {
    
        			$args=array(
        			$param_type => $tag->slug,
        			'post__not_in' => array($post->ID),
        			'post_type' => 'staff-member',
        			'showposts'=> 4,
        			'caller_get_posts'=> 1 );
    
        		$my_query = null;
        		$my_query = new WP_Query($args);
        		if( $my_query->have_posts() ) {
    			echo '<h2>Related Posts</h2>';
        		while ($my_query->have_posts()) : $my_query->the_post(); ?>
        		<h3><a>" rel="bookmark" title="<?php echo '<b>Name:</b> '.$name; ?>"><?php echo '<b>Name:</b> '.$name; ?></a></h3>
        		<?php $found_none = '';
        		endwhile;
        		}
        	}
        }
        wp_reset_query(); // to use the original query again  ?>

    [Please post code or markup between backticks or use the code button. Or better still - use a pastebin. Your posted code has now been permanently damaged/corrupted by the forum's parser.]

    Just returns a blank. Where did I go wrong??

Topic Closed

This topic has been closed to new replies.

About this Topic