dongyuzhu2244 2016-10-04 01:20
浏览 68
已采纳

单击用户图像时的Showwordpress用户说明

I am working on an existing wordpress site. I am updating a page that displays the users in clickable images. When the image is clicked a dropdown box is supposed to display the users name and description. The problem I am having is, the dropdown box is only displaying the name and description of the last user on the page. The information in the dropdown is not matching up with the image clicked. Any help is greatly appreciated!

Here is the HTML/PHP:

<section class="series">
        <div class="container-fluid">
            <?php //query for hosts/contributor users
            $cq = new WP_User_Query(array('role'=>'contributor'));

            // User Loop
            if(!empty($cq->results))
            {
                //sort users into current and past by meta field//
                $hosts = $cq->results;
                $current_hosts = array();

                foreach($hosts as $user)
                {
                    $user->sort_num = get_field('order', "user_$user->ID");

                    if(tv_is_host_active($user->ID))
                        $current_hosts[] = $user;
                    else
                        $past_hosts[] = $user;

                }
                usort($current_hosts, 'tv_compare_hosts');


                //display the current hosts
                $row_counter = 0;
                foreach ( $current_hosts as $user )
                {
                    //add rows of four
                    if($row_counter++ % 4 == 0)
                    {
                        echo "<div class='row'
>";
                    } ?>

                    <div class="col-lg-3 col-md-3 col-sm-6 col-xs-12">
                        <a class="card card-cast" href="javascript:void(0)">
                            <div class="card-img-cast">
                                <?php if(get_field('profile_picture', "user_".$user->ID)): $image = get_field('profile_picture', "user_".$user->ID); ?>
                                <img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>"  />
                                <?php else: ?>
                                <img src="<?php bloginfo('stylesheet_directory'); ?>/img/thumbholder-medium.png" alt="winchester logo" />
                                <?php endif;?>
                            </div>
                            <div class="card-content">
                                <div class="card-title"><?php echo $user->data->display_name; ?></div>
                            </div>
                        </a>
                    </div>
                    <?php
                //add rows of 4
                    if($row_counter % 4 == 0)
                    {
                        echo "</div><!-- end row-->
";
                    }

            } //end foreach of current hosts


            //cap row if the last row was not full
            if(!($row_counter % 4 == 0))
            {
                echo "</div><!-- end/cap row-->
";
            }
            ?>

            <?php
        } else { ?>

            <div class="col-xs-12 col-sm-4 host">
                <p>No hosts found.</p>
            </div>
            <div class="clearfix visible-xs">&nbsp;</div>
            <?php
        }

        ?>
            <?php endwhile;
            endif; //end main loop ?>
        <!-- cast profile dropdown -->
        <div class="container-fluid profile-details hidden">
        <i class="fa fa-times closeBox" aria-hidden="true"></i>
        <h3 class="member-name"><?php echo $user->data->display_name; ?></h3>
        <p class=".text-white"><?php echo tv_host_shows($user->ID); ?></p>
        <p class="member-description"><?php echo get_user_meta($user->ID, 'description', true); ?></p>
        <div class="row">
            <div class="col-xs-12">
                <ul class="list-inline social">
                    <?php if(get_field('facebook_profile_link', "user_".$user->ID)): ?>
                        <li><a data-toggle="tooltip" data-placement="top" data-original-title="Like <?php echo $user->data->display_name; ?> On Facebook" href="<?php the_field('facebook_profile_link', "user_".$user->ID); ?>"><i class="fa fa-facebook"></i></a></li>
                    <?php endif;
                    if(get_field('twitter_profile_link', "user_".$user->ID)): ?>
                    <li><a data-toggle="tooltip" data-placement="top" data-original-title="Follow <?php echo $user->data->display_name; ?> On Twitter" href="<?php the_field('twitter_profile_link', "user_".$user->ID); ?>"><i class="fa fa-twitter"></i></a></li>
                    <?php endif;
                    if(get_field('youtube_channel_link', "user_".$user->ID)): ?>
                    <li><a data-toggle="tooltip" data-placement="top" data-original-title="Watch <?php echo $user->data->display_name; ?> On Youtube" href="<?php the_field('youtube_channel_link', "user_".$user->ID); ?>"><i class="fa fa-youtube"></i></a></li>
                    <?php endif;
                    if(get_field('website', "user_".$user->ID)): ?>
                    <li><a data-toggle="tooltip" data-placement="top" data-original-title="See the website of <?php echo $user->data->display_name; ?>" href="<?php the_field('website', "user_".$user->ID); ?>"><i class="fa fa-globe"></i></a></li>
                    <?php endif; ?>
                </ul>
            </div>
        </div><!-- end social link row -->
        </div><!-- end dropdown --> 
        </div><!--end container-->
    </section>

</main><!--end .main-bg -->
<script>
    jQuery(document).ready(function() {
        initHostsPage();
    });
</script>

<?php

get_footer(); ?>

and the jquery function to show dropdown box:

function initHostsPage() {
    $('.social').each(function(key, val){
        $(this).children('li').children('a').tooltip();
    });

        //dropdown profile box
    $('.card').click(function() {
        var row = $(this).closest('.row');
        var profileDetails = $('.profile-details');
        profileDetails.removeClass('hidden');
        row.append(profileDetails);

        if((profileDetails).is(':hidden')) {
            profileDetails.slideTogle('slow');
        }

        else{
            profileDetails.hide();
        } 
    });

    $(".closeBox").click(function() {
        $(this).parent().hide();
    });
}
  • 写回答

2条回答 默认 最新

  • dputlf5431 2016-10-05 15:21
    关注

    HTML/PHP:

    <section class="series">
            <div class="container-fluid">
                <?php //query for hosts/contributor users
                $cq = new WP_User_Query(array('role'=>'contributor'));
    
                // User Loop
                if(!empty($cq->results))
                {
                    //sort users into current and past by meta field//
                    $hosts = $cq->results;
                    $current_hosts = array();
    
                    foreach($hosts as $user)
                    {
                        $user->sort_num = get_field('order', "user_$user->ID");
    
                        if(tv_is_host_active($user->ID))
                            $current_hosts[] = $user;
                        else
                            $past_hosts[] = $user;
    
                    }
                    usort($current_hosts, 'tv_compare_hosts');
    
    
                    //display the current hosts
                    $row_counter = 0;
                    foreach ( $current_hosts as $user )
                    {
                        //add rows of four
                        if($row_counter++ % 4 == 0)
                        { 
                            echo "<div class='row'
    >";
                        } ?>
    
                        <div class="col-lg-3 col-md-3 col-sm-6 col-xs-12">
                            <a data-id="<?php echo $user->ID;?>" class="card-cast" href="javascript:void(0)">
                                <div class="card-img-cast">
                                    <?php if(get_field('profile_picture', "user_".$user->ID)): $image = get_field('profile_picture', "user_".$user->ID); ?>
                                    <img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>"  />
                                    <?php else: ?>
                                    <img src="<?php bloginfo('stylesheet_directory'); ?>/img/thumbholder-medium.png" alt="winchester logo" />
                                    <?php endif;?>
                                </div>
                                <div class="card-content">
                                    <div class="card-title"><?php echo $user->data->display_name; ?></div>
                                </div> 
                            </a> 
                        </div> 
    
                        <!-- cast profile dropdown -->
                        <div class="profile-details profile-<?php echo $user->ID;?> hidden">
                            <i class="fa fa-times closeBox" aria-hidden="true"></i>
                            <h3 class="member-name"><?php echo $user->data->display_name; ?></h3>
                            <p class=".text-white"><?php echo tv_host_shows($user->ID); ?></p>
                            <p class="member-description"><?php echo get_user_meta($user->ID, 'description', true); ?></p>
                            <div class="row">
                                <div class="col-xs-12">
                                    <ul class="list-inline social">
                                        <?php if(get_field('facebook_profile_link', "user_".$user->ID)): ?>
                                            <li><a data-toggle="tooltip" data-placement="top" data-original-title="Like <?php echo $user->data->display_name; ?> On Facebook" href="<?php the_field('facebook_profile_link', "user_".$user->ID); ?>"><i class="fa fa-facebook"></i></a></li>
                                        <?php endif;
                                        if(get_field('twitter_profile_link', "user_".$user->ID)): ?>
                                        <li><a data-toggle="tooltip" data-placement="top" data-original-title="Follow <?php echo $user->data->display_name; ?> On Twitter" href="<?php the_field('twitter_profile_link', "user_".$user->ID); ?>"><i class="fa fa-twitter"></i></a></li>
                                        <?php endif;
                                        if(get_field('youtube_channel_link', "user_".$user->ID)): ?>
                                        <li><a data-toggle="tooltip" data-placement="top" data-original-title="Watch <?php echo $user->data->display_name; ?> On Youtube" href="<?php the_field('youtube_channel_link', "user_".$user->ID); ?>"><i class="fa fa-youtube"></i></a></li>
                                        <?php endif;
                                        if(get_field('website', "user_".$user->ID)): ?>
                                        <li><a data-toggle="tooltip" data-placement="top" data-original-title="See the website of <?php echo $user->data->display_name; ?>" href="<?php the_field('website', "user_".$user->ID); ?>"><i class="fa fa-globe"></i></a></li>
                                        <?php endif; ?>
                                    </ul>
                                </div>
                            </div><!-- end social link row -->
                        </div><!-- end dropdown --> 
    
                        <?php
                    //add rows of 4
                        if($row_counter % 4 == 0)
                        {
                            echo "</div><!-- end row-->
    ";
                        }
                } //end foreach of current hosts?>
    
            </div><!-- end Container -->
    
                <?php
                    } else { ?>
    
                        <div class="col-xs-12 col-sm-4 host">
                            <p>No hosts found.</p>
                        </div>
                        <div class="clearfix visible-xs">&nbsp;</div>
                    <?php
                    }
    
                    ?>
                <?php endwhile;
                endif; //end main loop ?>
    
        </section>
    
    </main><!--end .main-bg -->
    <script>
        jQuery(document).ready(function() {
            initHostsPage();
        });
    </script>
    
    <?php
    
    get_footer(); ?>
    

    and the Javascript:

    function initHostsPage() {
        $('.social').each(function(key, val){
            $(this).children('li').children('a').tooltip();
        });
    
            //dropdown profile box
        $('.card-cast').click(function() {
            var row = $(this).closest('.row');
            var id = $(this).data('id'); //get the card
            var profileDetails = $('.profile-' + id); //get the exact profile
            profileDetails.removeClass('hidden');
            row.append(profileDetails);
    
            if((profileDetails).is(':hidden')) {
                profileDetails.slideToggle('slow');
            }
    
            else{
                profileDetails.hide();
            } 
        }); 
    
        $(".closeBox").click(function() {
            $(this).parent().hide();
        });
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 组策略中的计算机配置策略无法下发
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)
  • ¥50 mac mini外接显示器 画质字体模糊
  • ¥15 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写
  • ¥20 Qcustomplot缩小曲线形状问题