0

I have one custom post type 'team' to create and display team-members and all works fine (screenshot how it needs to look):

enter image description here

In admin panel user entries team member position into input field and attach featured image and publish post and all works fine.

but last item of the list of team member it's image with link "SEND CV" when all previous items it's image with team member position without any links. So I need to create another custom post type just for this one image with link or it's any way I can change last post to have link instead of position?

Here is my query:

<?php

                    $query = new WP_Query(array(
                        'post_type' => array('team'),
                        'orderby' => 'menu_order',
                        'order' => 'ASC',
                    ));

 if ($query->have_posts()) {
                        while ($query->have_posts()) {
                            $query->the_post(); ?>

                            <li class="col-lg-3 d-flex text-center">
                                <div class="team-member-wrapper text-center mx-auto">
                                <div class="img-border">
                                    <?php
                                    the_post_thumbnail('full', array('class' => 'team-member-img img-fluid'));
                                    ?>
                                </div>
                                <?php
                                echo '<span class="team-member-position">' . get_post_meta(get_the_ID(), 'position', true) . '</span>';
                                ?>
                                </div>
                            </li>
                            <?php
                        }
                    } else {

                    }
                    wp_reset_query();
                    wp_reset_postdata(); ?>
  • you can make that just in testing in the template with something like if (lastElement) { .... edit your question to show how you generate the others entries. – mmm Feb 10 '18 at 22:03
  • @mmm added my query. In the last post I need to have anchor instead of span which I have. – Belial Feb 10 '18 at 22:08
  • The team is a short loop, You can use Widgets for short loops. – Sinac Feb 11 '18 at 6:04
1

Here are some options I think you can try:

First Option:

If you always have that element in your archive page, you can add this element at the end of the list outside the loop. It should look something like this:

<?php
     $query = new WP_Query(array(
         'post_type' => array('team'),
         'orderby' => 'menu_order',
         'order' => 'ASC',
     ));

 if ($query->have_posts()) {
     while ($query->have_posts()) {
         $query->the_post(); ?>

         <li class="col-lg-3 d-flex text-center">
             <div class="team-member-wrapper text-center mx-auto">
                 <div class="img-border">
                 <?php
                     the_post_thumbnail('full', array('class' => 'team-member-img img-fluid'));
                 ?>
                 </div>
                 <?php
                     echo '<span class="team-member-position">' . get_post_meta(get_the_ID(), 'position', true) . '</span>';
                 ?>
             </div>
         </li>
                <?php
     }
     ?>
     <!-- This is where your last Send CV Element will go -->
     <?php
} else {

}
wp_reset_query();
wp_reset_postdata(); ?>

2nd Option

You can add a meta box in the post editor and create a send cv post and mark it as a send cv type. Then you can check for it in the front end.

0

add a link field to every team member and do an if else statement in your loop. if the link field is there... link it, otherwise don't.

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.