M
M
Mogambus2021-07-28 23:02:05
WordPress
Mogambus, 2021-07-28 23:02:05

Why is pagination not working on the archive page?

Good day.
There was a problem with the performance of pagination on the archive page.
I'm trying to make the following structure:
site.ru/karkasnye/taxonomy/ - I rewrote the taxonomy karkasnye via rewrite to karkasnye
site.ru/proekty_domov/karkasnye/dom/ - added the path proekty_domov/ via rewrite

Pagination by link - site.ru/proekty_domov/karkasnye/ - works
Pagination by link - site.ru/karkasnye/ - displayed, but does not work

Ideally, of course, make a structure:
site.ru/proekty_domov/karkasnye/dom/ - for houses
site.ru/proekty_domov/karkasnye/taxonomy/ - for houses

I rummaged through a bunch of information, tried a lot of ways, and as far as I understood, this would not work. Am I wrong?

Post registration and taxonomy:

register_taxonomy('karkasnyi', array('karkasnye'), array(
    'label'                 => 'Каркасные дома',
    'labels'                => array(
      'name'              => 'Каркасные дома',
      'singular_name'     => 'Каркасные дома',
      'search_items'      => 'Искать Каркасный дом',
      'all_items'         => 'Все Каркасные дома',
      'parent_item'       => 'Родит. раздел Каркасных домов',
      'parent_item_colon' => 'Родит. раздел Каркасных домов:',
      'edit_item'         => 'Ред. Раздел Группы Каркасных домов',
      'update_item'       => 'Обновить категорию Каркасные дома',
      'add_new_item'      => 'Добавить категорию Каркасные дома',
      'new_item_name'     => 'Новый Раздел Каркасных домов',
      'menu_name'         => 'Категории Каркасных домов',
    ),
    'description'           => 'Рубрика Каркасных домов', 
    'public'                => true,
    'show_in_nav_menus'     => false, 
    'show_ui'               => true, 
    'show_tagcloud'         => false, 
    'hierarchical'          => false,
    
    'show_admin_column'     => true, 
    'rewrite'       => array( 'slug' => 'karkasnye', 'with_front' => false ),
  ) );

  register_post_type('karkasnye', [
    'labels' => array(
      'name'               => 'Каркасные дома',
      'singular_name'      => 'Каркасный дом',
      'add_new'            => 'Добавить Каркасный дом', 
      'add_new_item'       => 'Добавление Каркасного дома', 
      'edit_item'          => 'Редактирование Каркасного дома',
      'new_item'           => 'Новый Каркасный дом', 
      'view_item'          => 'Смотреть Каркасный дом', 
      'search_items'       => 'Искать Каркасный дом', 
      'not_found'          => 'Не найдено', 
      'not_found_in_trash' => 'Не найдено в корзине',
      'parent_item_colon'  => '',
      'menu_name'          => 'Каркасные дома', 
    ),
    'public'              => true,
    'menu_position'       => 82,
    'menu_icon'           => 'dashicons-star-filled', 
    'hierarchical'        => true,
    'supports'            => array('title', 'editor', 'thumbnail'),
    'has_archive'         => true,
    //'taxonomies'          => array( 'proekty_domov/karkasnyi'),
    'rewrite'       => array( 'slug' => 'proekty_domov/karkasnye', 'with_front' => false ),
  ]);


Output from archive page:
$args = array(
       'post_type'  => 'karkasnye',
        'posts_per_page' => 1,
        'paged' => ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1,
 );
$query = new WP_Query( $args );
<?php if($query->have_posts()) : ?>
  <?php while($query->have_posts()) : $query->the_post(); ?>
...
 <?php endwhile; ?>
<?php endif; ?>
 <?php
    $args = array(
         'base'         => str_replace( 999999999, '%#%', esc_url( get_pagenum_link( 999999999 ) ) ),
          'total'        => $query->max_num_pages,
          'current'      => max( 1, get_query_var( 'paged' ) ),
          'format'       => '?paged=%#%',
          'show_all'     => false, 
          'prev_next'    => true,
          'mid_size'     => 4,
          'end_size'     => 1,
          'add_args'     => false, 
          'add_fragment' => '',   
          'screen_reader_text' => __( '' ),
         );
  echo paginate_links($args); wp_reset_query();?>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Artem Zolin, 2021-07-29
@Mogambus

Because the archive page already has a global post query, there is WP_Query()no need to call a new one. Open any twenty theme and see what the archive.php template should look like , and you can safely remove this gag

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question