Wordpress Pagination Sorunu
Merhaba, wordpress ile pagination yapmaya çalışıyorum fakat şöyle bir sorunum var, kaç sayfa var ise o kadar pagination gösteriyor. Mesela listelenmesi gereken 3 sayfa var ise 3 tane pagination gösteriyor.
pagination ile alakalı araştırma yaptığımda, foreach kullanmadıklarını gördüm. fakat custom post taxonomy'si kullandığım için foreach kullanmak zorundayım galiba.
Yardımlarınız için şimdiden teşekkür ederim.
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$difficultys = get_terms('difficulty2');
foreach ($difficultys as $difficulty2) {
wp_reset_query();
$args = array('post_type' => 'server',
'posts_per_page' => 1,
'paged' => $paged,
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'difficulty2',
'field' => 'slug',
'terms' => $difficulty2->slug
),
),
);
$loop = new WP_Query($args);
if($loop->have_posts()) {
while($loop->have_posts()) : $loop->the_post();
echo '<tr class="responsive-table__row">';
echo '<td class="responsive-table__body__text responsive-table__body__text--name"><a href="'.get_permalink().'">'.get_the_title().'</a></td>';
echo '<td class="responsive-table__body__text responsive-table__body__text--status">'.$difficulty2->name.'</td>';
echo '<td class="responsive-table__body__text colums3 responsive-table__body__text--status">'.get_the_author().'</td>';
echo '</tr>';
endwhile;
}
$total_pages = $loop->max_num_pages;
if ($total_pages > 1){
$current_page = max(1, get_query_var('paged'));
echo paginate_links(array(
'base' => get_pagenum_link(1) . '%_%',
'format' => '/page/%#%',
'current' => $current_page,
'total' => $total_pages,
'prev_text' => __('« prev'),
'next_text' => __('next »'),
)
);
}
}
$loop = new WP_Query($args);
if($loop->have_posts()) {
while($loop->have_posts()) : $loop->the_post();
echo '<tr class="responsive-table__row">';
echo '<td class="responsive-table__body__text responsive-table__body__text--name"><a href="'.get_permalink().'">'.get_the_title().'</a></td>';
echo '<td class="responsive-table__body__text responsive-table__body__text--status">'.$difficulty2->name.'</td>';
echo '<td class="responsive-table__body__text colums3 responsive-table__body__text--status">'.get_the_author().'</td>';
echo '</tr>';
endwhile;
}
$total_pages = $loop->max_num_pages;
if ($total_pages > 1){
$current_page = max(1, get_query_var('paged'));
echo paginate_links(array(
'base' => get_pagenum_link(1) . '%_%',
'format' => '/page/%#%',
'current' => $current_page,
'total' => $total_pages,
'prev_text' => __('« prev'),
'next_text' => __('next »'),
)
);
}
bunu foreachden çıkar
o zaman 1 pagination gösterir