0

I want to build a page with the members of a team. Because I have too many members, I want to group them by department. Therefore, I created a custom post type TEAM with taxonomy by department

I use the following code to display the team members. I created a new page template.

 <?php 
$team_posts = get_posts( array(
    'post_type' => 'team',
    'posts_per_page' => -1, // Unlimited posts
    'orderby' => 'title', // Order alphabetically by name
) );

    foreach ( $team_posts as $post ): 
    setup_postdata($post);

    $thumb_src = null;
    if ( has_post_thumbnail($post->ID) ) {
        $src = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'team-thumb' );
        $thumb_src = $src[0];
    }
    ?>
    <article class="seven columns team_lid">
        <div class="tm_header">
            <?php if ( $thumb_src ): ?>
            <img src="<?php echo $thumb_src; ?>" alt="<?php the_title(); ?>, <?php the_field('team_position'); ?>" class="img-circle">
            <?php endif; ?>
        </div>

        <div class="tm-content">
            <h3><?php the_title(); ?></h3>
            <p class="lead position"><?php the_field('team_position'); ?></p>
            <i class="fa fa-mobile contact_icoon"></i><?php the_field('team_phone'); ?><br/>
            <i class="fa fa-mobile contact_icoon"></i><?php the_field('mobile_phone'); ?><br/>

            <i class="fa fa-envelope contact_icoon"></i><a href="<?php the_field('team_email'); ?>"><?php the_field('team_email'); ?></a>
            <div class="content_tekst">
            <?php the_content(); ?>
            </div>
        </div>
    </article><!-- END seven columns -->
    <?php endforeach; ?>

This is all working well, but as you can see this code displays all the team members no matter in which department they are.

Can somebody help me with this matter? I want to have the different departments with the team members on 1 page template. Which functions do I have to use.

  • Post the code that sets the $team_posts variable. – s_ha_dum May 6 '14 at 11:05
  • @s_ha_dum See my edit. – Niels Jansen May 6 '14 at 13:02
0

Follow these steps .

Add the following code to your functions.php

 add_shortcode( 'list-team', 'list_team_members' );
function list_team_members( $atts ) {
    ob_start();

    // define attributes and their defaults
    extract( shortcode_atts( array (
        'type' => 'post',
        'posts' => 5,
        'category' => '',
    ), $atts ) );

    // define query parameters based on attributes
    $options = array(
        'post_type' => $type,
        'posts_per_page' => $posts,
        'category_name' => $category,
    );
    $query = new WP_Query( $options );
    // run the loop based on the query
    if ( $query->have_posts() ) { ?>
        <ul class="">
            <ul class="">
                <li id="post-<?php the_ID(); ?>">></li>
            </ul>
        </ul>
    <?php
        $myvariable = ob_get_clean();
        return $myvariable;
    }
}

and then call any department - [list-team category=" "]

You dont need to create specific template files for this...

shortcodes will do for you..

I wrote this in little hurry...

you can get full code at http://code.tutsplus.com/tutorials/create-a-shortcode-to-list-posts-with-multiple-parameters--wp-32199

  • thanks for the help. I will check it but i rather prefer template files because I want to use a different lay-out on my team page – Niels Jansen May 6 '14 at 13:05
  • your wish... you could still create a custom template with different layout and add shortcode for adding team members... – Anirudh babbar May 7 '14 at 7:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.