Answer the question
In order to leave comments, you need to log in
Why is pagination not working in Wordpress?
there is a code for displaying posts from the parent category
<section class="product">
<?php
$parent_id = 5;
# получаем дочерние рубрики
$sub_cats = get_categories( array(
'child_of' => $parent_id,
'hide_empty' => 0
) );
if( $sub_cats ){
foreach( $sub_cats as $cat ){
# получаем записи из рубрики
$myposts = get_posts( array(
'numberposts' => 6,
'category' => $cat->cat_ID,
'orderby' => 'post_date',
'order' => 'DESC',
) );
# выводим записи
global $post;
echo '<div class="prod-item">';
echo '<h3 class="catt">'. $cat->name .'</h3>';
foreach($myposts as $post){
setup_postdata($post);
echo '<div class="entry col-md-6 ' . $cat->category_nicename . '"><div class="right">';
echo '<h3 class="entry-title video"><a href="'. get_permalink() .'">'. get_the_title() .'</a></h3></div>';
echo '<div class="left"><div class="entry-thumb"><a href="' . get_permalink() . '">' . get_the_post_thumbnail( $page->ID, 'full') . '</a></div>';
echo mb_substr( strip_tags( get_the_content() ), 0, 120 ) . '</div></div>';
}
echo '</div>';
wp_reset_postdata(); // сбрасываем глобальную переменную пост
}
};?>
</section>
<?php
the_posts_pagination( array(
'end_size' => 2,
'prev_text' => __('←'),
'next_text' => __('→'),
) );
?>
Answer the question
In order to leave comments, you need to log in
I figured it out myself, maybe it will help someone:
Custom cycles in wordpress must contain the 'paged' parameter, otherwise wordpress "does not understand" which pagination page should be displayed. Example:
<section class="product">
<?php
$parent_id = 5;
# получаем дочерние рубрики
$sub_cats = get_categories( array(
'child_of' => $parent_id,
'hide_empty' => 0
) );
if( $sub_cats ){
foreach( $sub_cats as $cat ){
# получаем записи из рубрики
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$myposts = get_posts( array(
'numberposts' => 6,
'category' => $cat->cat_ID,
'orderby' => 'post_date',
'order' => 'DESC',
'paged' => $paged,
) );
# выводим записи
global $post;
echo '<div class="prod-item">';
echo '<h3 class="catt">'. $cat->name .'</h3>';
foreach($myposts as $post){
setup_postdata($post);
echo '<div class="entry col-md-6 ' . $cat->category_nicename . '"><div class="right">';
echo '<h3 class="entry-title video"><a href="'. get_permalink() .'">'. get_the_title() .'</a></h3></div>';
echo '<div class="left"><div class="entry-thumb"><a href="' . get_permalink() . '">' . get_the_post_thumbnail( $page->ID, 'full') . '</a></div>';
echo mb_substr( strip_tags( get_the_content() ), 0, 120 ) . '</div></div>';
}
echo '</div>';
wp_reset_postdata(); // сбрасываем глобальную переменную пост
}
};?>
</section>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question