如何在Wordpress的自定义for循环中添加分页。我在自定义页面模板中有一个自定义for循环,我想在页面上只显示10个结果。如何添加分页。
请在下面找到我的代码。任何帮助都会很感激。
<div class="vender-bg col-sm-12">
<div class="row">
<?php
global $wpdb;
$user_meta = $wpdb->get_results("SELECT * FROM wp_usermeta WHERE meta_key='yith_product_vendor_owner'");
for ($i = 0; $i <= count($user_meta)-1; $i++) {
$value = $user_meta[$i]->meta_value;
$term_meta = $wpdb->get_row("SELECT * FROM wp_terms WHERE term_id=$value");
$vendor_name = $term_meta->name;
$vendor_slug = $term_meta->slug;
$taxonomy_meta = $wpdb->get_row("SELECT * FROM wp_term_taxonomy WHERE term_id=$value and taxonomy='yith_shop_vendor'");
$description = $taxonomy_meta->description;
$header_image_meta = $wpdb->get_row("SELECT * FROM wp_woocommerce_termmeta WHERE woocommerce_term_id=$value and meta_key='header_image'");
?>
<div class="col-sm-4 col-md-3 vender vender-all">
<div class="vender-cont">
<div class="vender-img"><a href="<?php echo site_url(); ?>/vendor/<?php echo $vendor_slug; ?>">
<?php
if (@$header_image_meta) {
$post_id = $header_image_meta->meta_value;
$post = get_post($post_id);
?><img class="" src="<?php echo $post->guid; ?>"><?php
} else {
?>
<img class="center-block" src="<?php echo get_template_directory_uri(); ?>/images/noimg.png">
<?php }
?>
</a>
</div>
<p class="vender-name"><?php echo $vendor_name; ?></p>
<p class="vender-text"><?php
$length = strlen($description);
if ($length > 75) {
$string = substr($description, 0, 75);
} else {
$string = $description;
}
if ($string !== $description)
$string .= '...';
echo $string;
?></p>
<div class="vender-b">
<a href="<?php echo site_url(); ?>/vendor/<?php echo $vendor_slug; ?>"> <button type="button" class="btn btn-danger">Shop Now</button></a>
</div>
</div>
</div>
<?php } ?>
</div>
</div>
答案 0 :(得分:0)
使用此处显示分页
<?php $pagination = get_the_posts_pagination(); ?>