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 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答