<?php
$paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1;
$args = array (
'posts_per_page' => 4,
'cat' => 7,
'paged' => $paged,
);
$catquery = new WP_Query( $args );
if( $catquery->have_posts() ):
while( $catquery->have_posts() ):
$catquery->the_post();
get_template_part( 'content', 'footer-post' );
endwhile;
endif;
wp_reset_postdata();
// Paginacja
$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' => $the_query->max_num_pages
) );
?>
Niestety nic się nie wyświetla po dodaniu tego kodu. Tzn. lista wpisów z kategorii się wyświetla, ale paginacji nadal nie widać.
Po komentarzu //Paginacja zamień na:
global $wp_query;
$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
) );
Niestety dalej to samo.
Kod:
<?php
$paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1;
$args = array (
'posts_per_page' => 4,
'cat' => 7,
'paged' => $paged,
);
$catquery = new WP_Query( $args );
if( $catquery->have_posts() ):
while( $catquery->have_posts() ):
$catquery->the_post();
get_template_part( 'content', 'footer-post' );
endwhile;
endif;
wp_reset_postdata();
// Paginacja
global $wp_query;
$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
) );
?>
Ile postów masz w tej kategorii?
Możesz podać adres strony?
Sprawdzałem dla kilku kategorii, gdzie mam 6 wpisów, 10, itd. więc na pewno jest >4.
Póki co nie mogę, bo leży na localhoscie, jak bardzo potrzeba, to przerzucę wersję roboczą na serwer.
Spróbuj jeszcze:
// Paginacja
$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' => $catquery->max_num_pages
) );
Super, pomogło. Tylko teraz jest inny problem.
Korzystam z czegoś takiego: https://jqueryui.com/tabs/
Czyli moje „tabsy” to są odpowiedniki kategorii.
Kod:
<div id="tabs">
<ul>
<li><a href="#tabs-1">Wszystkie</a></li>
<li><a href="#tabs-2">Fundacja</a></li>
<li><a href="#tabs-3">Pro-life</a></li>
<li><a href="#tabs-4">Bioetyka</a></li>
<li><a href="#tabs-5">Polityka</a></li>
</ul>
<div id="tabs-1">
<?php
$paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1;
$args = array (
'posts_per_page' => 2,
'cat' => 7,
'paged' => $paged,
);
$catquery = new WP_Query( $args );
if( $catquery->have_posts() ):
while( $catquery->have_posts() ):
$catquery->the_post();
get_template_part( 'content', 'footer-post' );
endwhile;
endif;
wp_reset_postdata();
// Paginacja
$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' => $catquery->max_num_pages
) );
?>
</div>
Paginacja się teraz wyświetla, ale nie działa, tzn. nie przechodzi do następnej strony, co jest spowodowane pewnie tymi tabsami z jquery. Da się to zrobić tak, aby przeładowało newsy na głównej, po kliknięciu w następną stronę, albo w taki sposób, aby po kliknięciu w daną stronę przeniosło do „archiwum kategorii”?