归档页面-分页问题

时间:2014-04-10 作者:Wojciech Parys

使用显示分页时出现问题WP_Query. 我创建了一个自定义页面,代码如下:

<?php
/*

Template name: Models

*/
?>
<?php get_header(); ?>
<?php the_post();?>
    <link rel="stylesheet" href="<?php echo get_template_directory_uri(); ?>/css/models.css">   
    <link rel="stylesheet" href="<?php echo get_template_directory_uri(); ?>/css/responsive-min.css">
<section id="galery" style="background-image:url(\'<?php the_field(\'tlo\');?>\');">
<div class="container">
<?php $kat = get_field(\'kategory\');?>
<?php $the_query = new WP_Query(array(\'post_type\' => \'modelki\', \'taxonomy\' => $kat, \'posts_per_page\' => \'4\')); ?>
<?php $i=1;?>
<?php if($the_query->have_posts()) : ?> 
    <?php while($the_query->have_posts()): $the_query->the_post(); ?>
    <article class="item">
        <a class="buka" href="#data-<?php echo $i;?>">
        <div class="layer"><span></span></div>
            <img src="<?php the_field(\'thumb\');?>" alt="buka">
        </a>
        <div class="text">
            <?php the_title(); ?>
            <a class="more buka" href="#data-<?php echo $i;?>">WIĘCEJ &nbsp; ></a>
        </div>      
        <div style="display:none">
            <div id="data-<?php echo $i;?>" class="fan">
                <?php $galeria = get_field(\'gallery\'); ?>
            <?php if( $galeria ): ?>
            <div class="swiper-fans buka-<?php echo $i; ?>">            
            <a class="arrow-left" href="#"></a> 
            <a class="arrow-right" href="#"></a>
              <div class="swiper-wrapper">                  
                <?php foreach( $galeria as $obrazek ): ?>
                    <div class="swiper-slide" style="background-image:url(\'<?php echo $obrazek[\'sizes\'][\'large\']; ?>\');"></div>
                <?php endforeach; ?>
              </div>
            </div>
            <?php endif;?>
                <div class="mym">
                    <h2><?php the_title();?></h2>
                    <div class="opis"><?php the_field(\'more_data\');?></div>
                </div>
            </div>
        </div>
    </article>
    <script type="text/javascript">
    $(function(){
      var myBuka = $(\'.buka-<?php echo $i; ?>\').swiper({
        mode:\'horizontal\',
        loop: true
      });
      $(\'.arrow-left\').on(\'click\', function(e){
        e.preventDefault();
        myBuka.swipePrev();
      })
      $(\'.arrow-right\').on(\'click\', function(e){
        e.preventDefault();
        myBuka.swipeNext();
      })
    })    
    </script>
    <?php $i++;?>
    <?php endwhile; ?>
<?php endif; ?>
<div class="pagination">
    <?php echo generatePagination(get_query_var(\'paged\'), $the_query); ?>
</div>
它应该可以工作,所有页面看起来都很好,但所有页面都只显示前四篇文章。

有什么建议吗?

2 个回复
最合适的回答,由SO网友:Wojciech Parys 整理而成

谢谢Pat J

I\'have got solution now(我现在有了解决方案):

<?php  $paged = (get_query_var(\'paged\')) ? get_query_var(\'paged\') : 1;  ?>
<?php $offset = ($paged - 1) * 4;?>
<?php $kat = get_field(\'kategory\');?>
<?php $query = new WP_Query(array(\'offset\' => $offset,\'post_type\' => \'modelki\', \'taxonomy\' => $kat, \'posts_per_page\' => \'4\')); ?>

SO网友:Dln

你在使用论点\'posts_per_page\' => \'4\'WP_Query.

这就是为什么每页只有4篇帖子出现的原因。

结束

相关推荐

Pagination problem

我有两个自定义重写规则:add_rewrite_rule(\'foo/bar/?\', \'index.php?post_type=foo\', \'top\'); add_rewrite_rule(\'foo/bar/([a-z]+)/?\', \'index.php?post_type=foo&bar=$matches[1]\', \'top\'); 这给了我匹配自定义变量的帖子bar. 然而,我也想处理分页,因此当一个数字成功时/bar/ wordpress应将其视为页码。