<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' => __( '← পূর্ববর্তী', 'ourdesh' ),
'next_text' => __( 'পরবর্তী →', 'ourdesh' ),
'before_page_number'=> '<b>',
'after_page_number'=> '</b>',
'show_all'=> false,
) );
?>
</div>
</div>
</div>
<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' => __( '← পূর্ববর্তী', 'ourdesh' ),
'next_text' => __( 'পরবর্তী →', 'ourdesh' ),
'before_page_number'=> '<b>',
'after_page_number'=> '</b>',
'show_all'=> false,
) );
?>
</div>
</div>
</div>
Share
Improve this question
edited Mar 30, 2019 at 7:33
nmr
4,5672 gold badges17 silver badges25 bronze badges
asked Mar 30, 2019 at 7:23
Md ShahinMd Shahin
11 bronze badge
2
- 2 Why do you use custom queries in there? Why don't you use the one created by WordPress? – Krzysiek Dróżdż Commented Mar 30, 2019 at 7:30
- 1 Welcome to WordPress development! Code-only questions are highly discouraged. Please update your question and tell us more about your exact issue and what you've tried so far. – norman.lol Commented Mar 30, 2019 at 8:57
1 Answer
Reset to default 0Category pagination not working in
category.php
please help me
Pagination is not working due to the fact that page executes the same queries every time.
From your OP code, it seems that you want to style 1st post differently than other.
If I understood your question correctly, you don't need to use custom queries, use the one created by WordPress -- the main query instead.
This may help.
<?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' => __( '← পূর্ববর্তী', 'ourdesh' ),
'next_text' => __( 'পরবর্তী →', 'ourdesh' ),
'before_page_number'=> '<b>',
'after_page_number'=> '</b>',
'show_all'=> false,
) );
?>
</div>
</div>