自定义页面中的用户分页 [英] Pagination of users in the custom page
本文介绍了自定义页面中的用户分页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个页面可以显示所有用户.用户类型为作者.显示所有代理.
I have a page to display all the users. The users type are author. To display the all the agent.
$args = array(
'role' => 's2member_level2',
'meta_query' => array(
array(
'key' => $filter,
'value' => $_GET['filter'],
'compare' => 'LIKE'
)
)
);
}
$users = get_users($args);
if ($users) {
foreach ($users as $user) {
$user_profile_data = get_user_meta($user->ID,'wp_s2member_custom_fields',true);
//print_r($user_profile_data);
echo '<div class="user_data" >';
echo '<a href="'.site_url().'/author/'.$user->user_login.'">'.user_avatar_get_avatar($user_info->ID,'110').'</a>';
echo '<div class="user-info">';
//print_r($users);
echo '<h6>'.'<a href="'.site_url().'/author/'.$user->user_login.'">'.$user->display_name.'</a></h6>';
if ($user_profile_data[contact_number])
echo '<p> call-'.$user_profile_data[contact_number].'</p>';
else
echo '<p> Phone number not specified.</p>';
echo '<p>'.$user->user_email.'</p>';
echo '</div>';
echo '<div class="agent_specify" >';
$agent_specify = $user_profile_data[posting_preferance];
echo '<p>Agent Speciality :</p>';
if ($agent_specify) {
echo '<ul>';
foreach ($agent_specify as $specification){
echo '<li>'.$specification.'</li>';
}
echo '</ul>';
}
else {
echo '<p style="font-weight: normal;">Not specified</p>';
}
echo '</div>';
echo '<a href="'.site_url().'/author/'.$user->user_login.'/#contact">contact »</a>';
echo '</div>';
}
}
else {
echo '<h4>No agents found.</h4>';
}
?>
</div>
我可以找到用户列表,但是我想在这里进行分页,因为页面上有很多用户.
I can find the user list, but i want to pagination here, because i have lot of users here in the page.
推荐答案
好的,您可以使用WP_User_Query()函数来完成此操作,而我为您做了一些工作.
ok you can use WP_User_Query() function for this juss check out and i did alittle bit of work for you.
$no=5;// total no of author to display
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
if($paged==1){
$offset=0;
}
else {
$offset= ($paged-1)*$no;
}
$args = array(
'role' => 's2member_level2',
'number' => $no, 'offset' => $offset,
'meta_query' => array(
array(
'key' => $filter,
'value' => $_GET['filter'],
'compare' => 'LIKE'
)
));
$user_query = new WP_User_Query( $args );
if ( !empty( $user_query->results ) ) {
foreach ( $user_query->results as $user ) {
..... ur code goes here
}
}
else {
echo '<h4>No agents found.</h4>';
}
对于分页,如果其永久链接为邮政名称,则取决于您的结构如何,那么您可以使用分页 代码为
And for pagination it depends oon how your structure is if its permalink is post name then you can use pagination code as
$total_user = $user_query->total_users;
$total_pages=ceil($total_user/$no);
echo paginate_links(array(
'base' => get_pagenum_link(1) . '%_%',
'format' => '?paged=%#%',
'current' => $paged,
'total' => $total_pages,
'prev_text' => 'Previous',
'next_text' => 'Next'
));
希望这对您有用:)
这篇关于自定义页面中的用户分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文