龙坤云服务器

B2主题教程 添加用户专栏独立页面 wordpress商业主题

释放双眼,带上耳机,听听看~!

实现方法是用了主题用户搜索结果页面的代码,然后添加了一个全局样式,本来想实现按照用户文章数量排序的,但是自己确实是小白一枚,有大神修改成功的话可以回帖交流一下。

演示地址:https://www.loncons.com/user_column

教程如下:

在主题Pages文件夹新建一个php文件,我这里命名为users.php,然后将下面代码粘贴过去。

<?php
/**
 *Template Name: 用户列表
 *
 *
 *
 */

get_header(); ?>
<?php


    $count = 20;

    $paged = get_query_var('paged') ? get_query_var('paged') : 1;
    $offset = ($paged -1)*$count;

    $users = new \WP_User_Query( array(
        'search_columns' => array(
            'display_name',
            'user_id'
        ),
        'number'=>$count,
        'offset'=>$offset
    ) );

    $users_found = $users->get_results();
    $total = $users->get_total();

    $pages = ceil($total/$count);


?>

<?php do_action('b2_normal_archive_before'); ?>
<div class="b2-single-content wrapper">
<div class="archive-row">
    <div id="user-list" class="">
        <?php $ids = array(); if($users_found){
            echo '<div class="hidden-line"><ul class="user-search-list" ref="searchUser">';
            
            foreach ($users_found as $user) {
                $user_data = B2\Modules\Common\User::get_user_public_data($user->ID);
                $user_lv = B2\Modules\Common\User::get_user_lv($user->ID);
                $user_vip = isset($user_lv['vip']['icon']) ? $user_lv['vip']['icon'] : '';
                $user_lv = isset($user_lv['lv']['icon']) ? $user_lv['lv']['icon'] : '';

                $tips = B2\Modules\Common\Comment::get_tips();
                $tips = $tips['title'] ? $tips['title'] : __('这家伙很懒,什么都没留下','b2');

                $following = get_user_meta($user->ID,'zrz_follow',true);
                $following = is_array($following) ? count($following) : 0;
                
                $followers = get_user_meta($user->ID,'zrz_followed',true);
                $followers = is_array($followers) ? count($followers) : 0;
                $ids[] = $user->ID;

                echo '<li>
                    <div>
                        <div class="user-s-cover"><img src="'.$user_data['cover'].'" class="cover"/><a href="'.$user_data['link'].'" class="link-block"></a></div>
                        <div class="user-s-info">
                        <a href="'.$user_data['link'].'" class="link-block"></a>
                            <div class="user-s-info-avatar avatar-parent">
                                <img src="'.$user_data['avatar'].'" class="avatar b2-radius" />
                                '.($user_data['user_title'] ? $user_data['verify_icon'] : '').'
                            </div>
                            <div class="user-s-info-name">
                                <h2>'.$user_data['name'].'</h2>
                                <p>'.$user_vip.$user_lv.'</p>
                            </div>
                        </div>
                        <div class="user-s-data">
                            <div class="">
                                <span>文章</span>
                                <p>'.count_user_posts($user->ID,'post').'</p>
                            </div>
                            <div class="">
                                <span>评论</span>
                                <p>'.B2\Modules\Common\Comment::get_user_comment_count($user->ID).'</p>
                            </div>
                            <div class="">
                                <span>粉丝</span>
                                <p>'.$followers.'</p>
                            </div>
                            <div class="">
                                <span>关注</span>
                                <p>'.$following.'</p>
                            </div>
                        </div>
                        <div class="user-s-info-desc">
                                '.($user_data['user_title'] ? $user_data['user_title'] : ($user_data['desc'] ? $user_data['desc'] : $tips)).'
                            </div>
                        <div class="user-s-follow">
                            <button class="author-has-follow" v-if="follow['.$user->ID.'] === true" v-cloak @click="followAc('.$user->ID.')">'.__('已关注','b2').'</button>
                            <button class="empty" v-else v-cloak @click="followAc('.$user->ID.')">'.__('关注','b2').'</button>
                            <button @click="dmsg('.$user->ID.')">'.__('私信','b2').'</button>
                        </div>
                    </div>
                </li>';
            }
            echo '</ul></div>';  
        ?>

        <?php }else{
            echo B2_EMPTY;
        } 
        unset($users_found);
        unset($users);
        wp_localize_script( 'b2-js-main', 'b2_search_data', array(
            'users'=>$ids
        ))
        ?>
    </div>
<?php do_action('b2_normal_archive_after'); ?>
<?php if($pages > 1){ ?>
    <div class="b2-pagenav post-nav">
        <?php echo b2_pagenav(array('pages'=>$pages,'paged'=>$paged)); ?>
    </div>
<?php } ?>
   
    
    </div>
<?php
get_footer();

 

在后台新建一个页面,页面模板选择新增的模板名称,如图提交,访问对应页面就实现了。

人已赞赏
源码插件网站运营

Contact form 7插件 设置文件上传教程 配合Contact Form Submissions插件实现后台记录

2020-7-6 18:50:25

网站运营

大商创教程手机红包广告设置简述

2020-7-16 21:33:33

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索