【问题标题】:Issues rendering pagination with WP_Query使用 WP_Query 呈现分页的问题
【发布时间】:2018-07-08 17:19:32
【问题描述】:

我在尝试呈现 Wordpress 分页时遇到了一个重大问题。我对 PHP 不是很好,我已经尝试了几乎所有我能用谷歌搜索的解决方案。一些查询“有效”,因为它们显示一组页码,但是当我添加更多变量时它们会中断。

例如,当我告诉它显示所有页面时,它就是这样做的,但是我无法使用 mid_size 或任何其他方法来限制它。所以这是一种“显示所有”(我不想要),或者什么都没有。我不确定发生了什么问题,因此任何朝着正确方向的推动都会非常好。

我的目标:创建一个正确截断的编号页面链接列表,如下所示:

[1 2 3 ... 97 98 99]

感谢任何可以帮助我的人。我正在运行 Wordpress 4.9.7。

我的代码如下所示:

<!-- post loop -->
<div class="auto cell">
<?php 
// the query
$wpb_all_query = new WP_Query(array('post_type'=>'review', 'posts_per_page' => 3, 'orderby'=>'name', 'order'=>'ASC')); ?>
 
<?php if ( $wpb_all_query->have_posts() ) : ?>
    <!-- start of main news loop -->
    <?php while ( $wpb_all_query->have_posts() ) : $wpb_all_query->the_post(); ?>
      <div class="grid-x grid-margin-x">
		<div class="cell large-2 small-2">
			<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>" class="thumbnail">
			<?php if ( has_post_thumbnail() ) {
				the_post_thumbnail();
			} else { ?>
			<img src="<?php bloginfo('template_directory'); ?>/img/default_thumb.png" alt="<?php the_title(); ?>" />
			<?php } ?></a>
		</div>
		
		<div class="cell large-10 small-10">
				<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
				<span class="post-meta"> By <?php the_author_posts_link(); ?> &middot; <?php the_time('F jS, Y, g:i A'); ?> <?php edit_post_link(__('Edit This'), ''); ?></span>
				<ul class="list-meta">
				<li>Developer: <?php echo(types_render_field( 'game-developer' )); ?></li>
				<li>Genre: <?php echo(types_render_field( 'game-genre' )); ?></li>
				</ul>
		</div>
		<div class="post-categories cell"><?php the_category(', '); ?></div>  
	</div>
    <?php endwhile; ?>
    <!-- start of pagination -->
  <div class="row">
 <?php if (function_exists("pagination")) {
          pagination($custom_query->max_num_pages);
      } ?>
  </div>
    <!-- end of pagination -->
    <!-- end of main news loop -->

【问题讨论】:

    标签: php wordpress pagination


    【解决方案1】:

    我使用this plugin 进行分页。它在后端为您提供了一个设置屏幕,您可以在其中设置它的编号方式。希望对您有所帮助!

    【讨论】:

      猜你喜欢
      • 2023-04-01
      • 2017-12-16
      • 1970-01-01
      • 2011-05-02
      • 1970-01-01
      • 1970-01-01
      • 2015-05-21
      • 2022-06-24
      • 1970-01-01
      相关资源
      最近更新 更多