2

I'm getting a taxonomy list page with pagination using this code :

<?php
$sortby = $_GET['sortby'];
if(isset($_GET['showall'])):
$args = array('hide_empty' => 0);
else:
$page = (get_query_var('paged')) ? get_query_var('paged') : 1;
$per_page = 1; //number of actores to show per page
$offset = ($page-1) * $per_page;
$args = array('number' => $per_page, 'offset' => $offset, 'hide_empty' => 0);
                        endif;
$taxonomy = 'actores';
$tax_terms = get_terms($taxonomy, $args);
?>
<?php foreach ($tax_terms as $cat) : ?>
<?php $flag = 0; if($sortby == substr($cat->name, 0, 1) || $sortby == '') {$flag = 1;} if($flag == '1') { ?>
<div class="td-block-span-actores">
<div class="td_module_3 td_module_wrap td-animation-stack">
<div class="td-module-image">
<div class="td-module-thumb-actores">
<a href="<?php echo get_term_link($cat->slug, 'actores'); ?>">
<?php $actores_image = z_taxonomy_image_url($cat->term_id); if(!empty($actores_image)) : ?>
<img src="<?php echo z_taxonomy_image_url($cat->term_id); ?>" alt title="<?php echo $cat->name; ?>" />
<?php else : ?>
<img src="<?php echo get_bloginfo('template_directory'); ?>/images/no-thumb/td_386x520.png" alt title="<?php echo $cat->name; ?>" />
<?php endif; ?>
</div>
<div class="entry-title td-module-title">
<a href="<?php echo get_term_link($cat->slug, 'actores'); ?>"><?php echo $cat->name; ?></a>
</div>
<span class="count">
<?php echo $cat->count; ?> <?php if($cat->count > 1) {
_e('Videos');
} else {
_e('Video');
} ?>
</span>
</div>
</div>
</div>
<?php } ?>
<?php endforeach; ?>
</div>
<?php
if(!isset($_GET['showall'])):
$total_terms = wp_count_terms('actores');
$pages = ceil($total_terms / $per_page);
if($pages > 1):
echo '<div class="page-nav td-pb-padding-side">';
echo paginate_links( array(
'base' => preg_replace('/\?.*/', '/', get_pagenum_link(1)) . '%_%',
'format' => 'page/%#%/',
'prev_text' => __('&laquo;'),
'next_text' => __('&raquo;'),
'total' => ceil($total_terms / $per_page),
'current' => $page,
));
echo '<div class="page-nav td-pb-padding-side"><a href="'.get_permalink().'?showall=true">Show all</a></div>';
echo "<span class=\"pages\">Page ".$paged." of ".$pages."</span>";
echo '</div>';
endif;
else:
echo '<div class="page-nav td-pb-padding-side"><a href="'.get_permalink().'">Show numeric pagination</a></div>';
endif;
?>

And this code for sortby letter function:

<?php
// a to z pagination
if(!function_exists('a_to_z_pagination')) {
function a_to_z_pagination() {
$order = isset($_REQUEST['sortby']) ? trim($_REQUEST['sortby']) : null;
$sort_array = array(
'A' =>  __('A'),
'B' =>  __('B'),
'C' =>  __('C'),
'D' =>  __('D'),
'E' =>  __('E'),
'F' =>  __('F'),
'G' =>  __('G'),
'H' =>  __('H'),
'I' =>  __('I'),
'J' =>  __('J'),
'K' =>  __('K'),
'L' =>  __('L'),
'M' =>  __('M'),
'N' =>  __('N'),
'O' =>  __('O'),
'P' =>  __('P'),
'Q' =>  __('Q'),
'R' =>  __('R'),
'S' =>  __('S'),
'T' =>  __('T'),
'U' =>  __('U'),
'V' =>  __('V'),
'W' =>  __('W'),
'X' =>  __('X'),
'Y' =>  __('Y'),
'Z' =>  __('Z'),
);
foreach ($sort_array as $key => $value) {
$active = ($order == $key) ? 'page-numbers current' : null;
$block .= '<a class="'.$active.'" href="'.get_permalink().'?sortby='.$key.'">'.$value.'</a>';
}
print $block;
}
add_action('a_to_z_pagination', 'a_to_z_pagination');
}

My problem is that i'm getting empty pages when i use the sortby letter...

Example:

I have 4 custom tax "actores"

1 tax per page

4 pages

tax slug: Ana, Brian, Carlos, Diana,

when i sortby letter "B" i get

page 1 - empty (actores/page/1/?sortby=B)

page 2 - Brian (actores/page/2/?sortby=B)

page 3 - empty (actores/page/3/?sortby=B)

page 4 - empty (actores/page/4/?sortby=B)

23
  • downvoted as question should be complete with all the data in them, including the relevant code. Commented Jun 5, 2017 at 3:59
  • @MarkKaplun Dear mark, IMHO it would be nicer to just edit the question, adding the missing data from the link and noting the OP about what he should do himself.
    – Johansson
    Commented Jun 5, 2017 at 4:04
  • @MarkKaplun sorry mark, code edited by jack :) Commented Jun 5, 2017 at 4:10
  • @JackJohansson, and then people will think I am a nice person.... can't let that happen. Anyway the chunks of code without no explanation what are they doing, are not a huge improvement (usually people that use pastebin just dump their whole code there, hiding the trees in the forest ;) ) Commented Jun 5, 2017 at 4:11
  • 1
    @MarkKaplun if you cant help me, stop commenting, dont be mad, it was my fault... Sorry buddy, i'm new here :D Commented Jun 5, 2017 at 4:42

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.