分类分页不起作用。php请帮帮我

时间:2019-03-30 作者:Md Shahin
<div class="col-sm-8 main-content">

        <div class="row">
            <div class="col-sm-12">
                <?php
                $cat_id = get_queried_object_id();
                $cat_slug = cat_slug($cat_id);
                $query = new WP_Query(array(
                    \'posts_per_page\' => \'1\',
                    \'post_type\' => \'post\',
                    \'category_name\' => $cat_slug
                ));
                while($query->have_posts()): $query->the_post();
                     ?>
                    <div class="single-block">
                        <div class="row">
                            <div class="col-sm-8">
                                <div class="img-box">
                                    <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
                                        <img src="<?php the_post_thumbnail_url(); ?>" style="height: 285px; object-fit: cover;" alt="">
                                    </a>
                                </div>
                            </div>
                            <div class="col-sm-4">
                                <div class="paddingRight10 paddingTop20">
                                    <h3 style="font-size:1.5em;line-height:34px;margin-bottom:10px;"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
                                    <?php
                                        readMore(20);
                                     ?>
                                </div>
                            </div>
                        </div>
                    </div>
                <?php endwhile; ?>
                </div>
            </div>
            <div class="row" id="loadMoreContent">
                <?php
                $cat_id = get_queried_object_id();
                $cat_slug = cat_slug($cat_id);
                $query = new WP_Query(array(
                    \'posts_per_page\' => \'\',
                    \'post_type\' => \'post\',
                    \'offset\' => \'1\',
                    \'category_name\' => $cat_slug
                ));
                while($query->have_posts()): $query->the_post();
                 ?>
                <div class="col-sm-6">
                    <div class="single-block cat-block">
                        <div class="row">
                            <div class="col-sm-5">
                                <div class="img-box">
                                    <a href="<?php the_permalink(); ?>" title="news-title"><img style="object-fit:cover;" src="<?php the_post_thumbnail_url(); ?>"></a>
                                </div>
                            </div>
                            <div class="col-sm-7">
                                <div class="paddingTop10 paddingRight10">
                                    <h3 style="font-size:1.1em;"><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"> <?php the_title(); ?> </a></h3>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <?php endwhile; ?>


            </div>
            <div class="text-center paddingBottom20">
                <div class="pagination pagination-sm">


                    <?php the_posts_pagination( array(
                            \'screen_reader_text\' => \' \', // this should hide the title
                            \'prev_text\'          => __( \'&larr; পূর্ববর্তী\', \'ourdesh\' ),
                            \'next_text\'          => __( \'পরবর্তী &rarr;\', \'ourdesh\' ),
                            \'before_page_number\'=> \'<b>\',
                            \'after_page_number\'=> \'</b>\',
                            \'show_all\'=> false,

                            ) );
                    ?>


                </div>
            </div>
        </div>
1 个回复
SO网友:Qaisar Feroz

类别分页不工作category.php 请帮帮我

分页不起作用,因为页面每次都执行相同的查询。

从您的操作码来看,您似乎希望第一篇文章的风格与其他文章不同。

If I understood your question correctly, 您不需要使用自定义查询,而是使用WordPress创建的查询——主查询。

这可能会有所帮助。

  <?php 

  global $wp_query;

  if( have_posts() ){

        while( have_posts() ){

              the_post();

              if ( $wp_query->current_post == 0 ){  // Check if it is 1st post


                 // Markup for 1st post


              } 

              else {


                  // Markup for all other posts


              }   // End else

        }// End: while(have_posts())

  }   //End: if(have_posts()) 

 ?>

        <div class="text-center paddingBottom20">
                <div class="pagination pagination-sm">
                    <?php the_posts_pagination( array(
                            \'screen_reader_text\' => \' \', // this should hide the title
                            \'prev_text\'          => __( \'&larr; পূর্ববর্তী\', \'ourdesh\' ),
                            \'next_text\'          => __( \'পরবর্তী &rarr;\', \'ourdesh\' ),
                            \'before_page_number\'=> \'<b>\',
                            \'after_page_number\'=> \'</b>\',
                            \'show_all\'=> false,

                            ) );
                    ?>
                </div>
        </div>

相关推荐

如何将自定义选项添加到wp_Dropdown_Categories?

我需要将自定义选项添加到wp_dropdown_categories. 现在,整个万维网世界还没有找到解决方案。。。因此,我在这里要求一个解决方案……因为我真的无法想象WordPress的开发人员没有考虑到这将永远不需要,对吗?