I am working on a website that is a customised WordPress installation running WP 5.2.4.
There are a number of categories, as follows:
- main_category (id 71)
- other_cat_1
- other_cat_2
- etc.
The post archives have been customised to display as follows:
When you go to… domain/category/main_category/ …everything is fine. It is using the default pagination settings, shows the default 10 posts per page as set in ‘Settings > Reading’ in the admin portal, has pagination links at the bottom. All fine.
If you look at any other category though e.g. … domain/category/other_cat/ …it shows 5 posts per page, and no pagination.
If you manually navigate to what would be page later pages, e.g. … domain/category/other_cat/page/2/ … it shows the same content as page 1.
I want to undo all this, and have all categories simply use the default pagination, number of post per page from ‘Reading’ settings, pagination links etc.
This is the archive.php code (I assume all changes will be here). I can see bits related to the problem here, e.g. “if($main_id==71)” which is the correctly working category. For the life of me though I can’t figure out how to get all the categories to work the same.
<?php
$queried_object = get_queried_object();
$main_id = $queried_object->term_id;
$taxo_desc = $queried_object->description;
get_header(); ?>
<section class="container-main">
<?php if(function_exists('demo_custom_innner_banner_code')) demo_custom_innner_banner_code(); ?>
<section class="inner-page blog-page">
<div class="container">
<div class="row">
<?php if($main_id==760) { ?>
<div class="col-12 col-md-12 col-lg-12 col-xl-12">
<?php } else { ?>
<div class="col-12 col-md-8 col-lg-9 col-xl-9">
<?php } ?>
<?php if ($taxo_desc ) { ?>
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
<?php echo wpautop($taxo_desc); ?>
</div>
</div>
<?php } ?>
<div class="blogs">
<?php $paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
$posts_per_page = get_option('posts_per_page');
if($main_id==71){
$perpost= $posts_per_page;
}else{
$perpost= 5;
}
if($main_id==760) {
$banner_args = array(
'posts_per_page' => $perpost,
'post_type' => 'post',
'orderby' => 'date',
'order' => 'DESC',
'cat' => 760,
'post_status' => 'publish'
);
}else{
$banner_args = array(
'posts_per_page' => $perpost,
'post_type' => 'post',
'orderby' => 'date',
'order' => 'DESC',
//'category__not_in' => 760 ,
'cat' => $main_id,
'post_status' => 'publish'
);
}
$banner_query = new WP_Query($banner_args);
if ($banner_query) {
?>
<?php if($main_id==71){ ?>
<?php while (have_posts()) { the_post();
$blog_title_post = get_the_title();
$blog_details_url = get_permalink();
$blog_content = strip_tags(get_the_content());
$news_image_url_sep = wp_get_attachment_image_src(get_post_thumbnail_id(), 'full');
if ($news_image_url_sep) {
$news_img_url = aq_resize($news_image_url_sep[0], 150, 150, true, false, true);
}
$news_image_url = $news_image_url_sep ? $news_img_url[0] : ';txt='.$blog_title_post.'&w=150&h=150';
if($blog_content) {
$blog_filter_cont = substr($blog_content ,0,250 ) . "...";
}
?>
<div class="blog">
<div class="blog-list-content">
<h5><a href="<?php echo $blog_details_url; ?>" title="<?php echo $blog_title_post; ?>"><?php echo $blog_title_post; ?></a></h5>
<?php if($main_id!=760) { ?>
<div class="comment-box">
<span class="blog_date"><?php echo get_the_time('F'); ?> <?php echo get_the_time('j'); ?>, <?php echo get_the_time('Y'); ?></span>
</div>
<?php } ?>
<p><?php echo strip_shortcodes( $blog_filter_cont );; ?></p>
<?php echo '<a href="'.$blog_details_url.'" title="Read More" class="link primary">Read More<span class="fa fa-angle-right"></span></a>'; ?>
<?php if($main_id!=760) { ?>
<?php } ?>
</div>
</div>
<?php } wp_reset_postdata(); ?>
<?php } else { ?>
<?php while ($banner_query->have_posts()) { $banner_query->the_post();
$blog_title_post = get_the_title();
$blog_details_url = get_permalink();
$blog_content = strip_tags(get_the_content());
$news_image_url_sep = wp_get_attachment_image_src(get_post_thumbnail_id(), 'full');
if ($news_image_url_sep) {
$news_img_url = aq_resize($news_image_url_sep[0], 150, 150, true, false, true);
}
$news_image_url = $news_image_url_sep ? $news_img_url[0] : ';txt='.$blog_title_post.'&w=150&h=150';
if($blog_content) {
$blog_filter_cont = substr($blog_content ,0,250 ) . "...";
}
?>
<div class="blog">
<div class="blog-list-content">
<h5><a href="<?php echo $blog_details_url; ?>" title="<?php echo $blog_title_post; ?>"><?php echo $blog_title_post; ?></a></h5>
<?php if($main_id!=760) { ?>
<div class="comment-box">
<span class="blog_date"><?php echo get_the_time('F'); ?> <?php echo get_the_time('j'); ?>, <?php echo get_the_time('Y'); ?></span>
</div>
<?php } ?>
<p><?php echo strip_shortcodes( $blog_filter_cont );; ?></p>
<?php echo '<a href="'.$blog_details_url.'" title="Read More" class="link primary">Read More<span class="fa fa-angle-right"></span></a>'; ?>
<?php if($main_id!=760) { ?>
<?php } ?>
</div>
</div>
<?php } wp_reset_postdata(); ?>
<?php } ?>
</div>
<?php if($main_id==71){
$big = 999999999; // need an unlikely integer
echo wpbeginner_numeric_posts_nav();
}
?>
<?php } ?>
</div>
<?php if($main_id!=760) { ?>
<?php get_sidebar(); ?>
<?php } ?>
</div>
</div>
</section>
</section>
<?php get_footer(); ?>
Thanks in advance for the help folks.