代码之家  ›  专栏  ›  技术社区  ›  Mark Tjan

使用WP\u查询呈现分页时出现的问题

  •  -1
  • Mark Tjan  · 技术社区  · 6 年前

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

    例如,当我告诉它显示所有页面时,它就这样做了,但是我不能使用mid\u大小或任何其他大小来限制它。所以这是一种“全部显示”(我不想要),或者什么都没有。我不确定是什么东西坏了,所以任何朝正确方向的推动都会很好。

    我的目标:创建一个正确截断的编号页面链接列表,使其看起来像:

    [ 1 2 3 ... 97 98 99 ]

    我的代码如下所示:

    <!-- 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 -->
    1 回复  |  直到 6 年前
        1
  •  0
  •   Derek Nolan    6 年前

    this plugin 为了我的分页。它在后端提供了一个设置屏幕,您可以在那里设置它的编号方式。希望有帮助!