Поддержка Проблемы и решения Тексономии и термы

Просмотр 1 ответа (всего 1)
  • пытаюсь пагинацию сделать

    
    <?php
    $post_type = 'doctor';
    $taxonomy = 'nosology';
    
    // count the number of terms for correct pagination
    $term_count = get_terms( array (
        'taxonomy' => $taxonomy,
        'fields'   => 'count',
    ) );
    
    // define the number of terms per page
    $terms_per_page = 3;
    
    // find out the number of pages to use in pagination
    $max_num_pages = ceil( $term_count / $terms_per_page );
    
    // get the page number from URL query
    $current_page = get_query_var( 'paged', 1 );
    
    // calculate the offset, if there is one.
    $offset = 0; // initial
    // or changed the if not the first (0)
    if( ! 0 == $current_page) {
        $offset = ( $terms_per_page * $current_page ) - $terms_per_page;
    }
    
    // get all taxonomy terms
    $terms = get_terms( array (
        'taxonomy' => $taxonomy,
        'order'    => 'ASC',
        'orderby'  => 'name',
        'number'   => $terms_per_page,
        'offset'   => $offset,
        'hide_empty' => 1,
    ) );
    
    // cycle through taxonomy terms
    foreach ( $terms as $term ) {
    
        echo '<h3 class="titleListSlider">' . $term->name . '</h3>';
        // cycle through posts having this term
        $items = get_posts( array (
            'post_type'   => $post_type,
            'tax_query'   => array(
                array(
                    'taxonomy' => $taxonomy,
                    'field'    => 'slug',
                    'terms'    => $term->slug,
                ),
            ),
            'numberposts' => -1, // different from WP_Query (see Code Ref)
        ) );
    
        // essential, see comments inside foreach() loop
        global $post;
    
        foreach ( $items as $item ) {
    
            // assign $item to global $post 
            $post = $item;
            // and now set up 
            setup_postdata( $post );
    
     ?>
    
      <div class="index-b-4-t rowVrach">
         <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>                                                
      </div>
    	
    
    <?php  }
        wp_reset_postdata();
        // end posts cycle
     }
    // end term cycle
    
    // Pagination
    echo paginate_links( array (
        'total'   => $max_num_pages,
        'current' => $current_page,
    	'show_all'     => false,
    	'end_size'     => 2,
    	'prev_text'    => __('« '),
    	'next_text'    => __(' »'),
    ) );
    
    $big = 999999999; // need an unlikely integer
    
    echo paginate_links( array(
    	'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
    	'format' => '?paged=%#%',
    	'current' => max( 1, get_query_var('paged') ),
    	'total' => $wp_query->max_num_pages
    ) );
    
    ?>
    

    так он читает все термы и выводит их, если я добавлю выборку
    …..
    foreach ( $terms as $term ) {
    $query = new WP_Query( array(
    ‘post_status’ => ‘publish’,
    ‘post_type’ => ‘doctor’,
    ‘posts_per_page’ => -1,
    ‘tax_query’ => array(
    array(
    ‘taxonomy’ => ‘nosology’,
    ‘field’ => ‘slug’,
    ‘terms’ => $term->slug,
    )
    )
    ));
    if ( ! $query->have_posts() ) continue;
    echo ‘<h3 class=»titleListSlider»>’ . $term->name . ‘</h3>’;
    // cycle through posts having this term
    …..`
    `
    то оно не правильно выводит по 3 на страницу, т.е. цикл выводит правильно по 3 на страницу, но если пропускает терм, то 1 или 2 получается….

Просмотр 1 ответа (всего 1)
  • Тема «Тексономии и термы» закрыта для новых ответов.