分类中的分页错误:警告:被零除

时间:2017-12-01 作者:Joel

我想按字母顺序列出分类法。我发现west代码可以这样做,但它会抛出一个错误:警告:除以零

功能。php

if( !function_exists(\'a_z_pagination\') ){
function a_z_pagination() {
$order = isset( $_REQUEST[\'sortby\'] ) ?  trim($_REQUEST[\'sortby\']) : null;
$sort_array = array(
\'A\' =>  __(\'A\',\'framework\'),
\'B\' =>  __(\'B\',\'framework\'),
\'C\' =>  __(\'C\',\'framework\'),
\'D\' =>  __(\'D\',\'framework\'),
\'E\' =>  __(\'E\',\'framework\'),
\'F\' =>  __(\'F\',\'framework\'),
\'G\' =>  __(\'G\',\'framework\'),
\'H\' =>  __(\'H\',\'framework\'),
\'I\'    =>   __(\'I\',\'framework\'),
\'J\'    =>   __(\'J\',\'framework\'),
\'K\' =>  __(\'K\',\'framework\'),
\'L\' =>  __(\'L\',\'framework\'),
\'M\' =>  __(\'M\',\'framework\'),
\'N\' =>  __(\'N\',\'framework\'),
\'O\' =>  __(\'O\',\'framework\'),
\'P\' =>  __(\'P\',\'framework\'),
\'Q\' =>  __(\'Q\',\'framework\'),
\'R\' =>  __(\'R\',\'framework\'),
\'S\' =>  __(\'S\',\'framework\'),
\'T\' =>  __(\'T\',\'framework\'),
\'U\' =>  __(\'U\',\'framework\'),
\'V\' =>  __(\'V\',\'framework\'),
\'W\' =>  __(\'W\',\'framework\'),
\'X\' =>  __(\'X\',\'framework\'),
\'Y\' =>  __(\'Y\',\'framework\'),
\'Z\' =>  __(\'Z\',\'framework\')
);
$block = \'\';
$block .= \'<div class="paginator lighter"><ul>\';
foreach ( $sort_array as $key=>$value ){
$active = ( $order == $key ) ? \'selected\' : null;
$block .= \'<li><a class="\'.$active.\'"  href="\'.get_permalink().\'?sortby=\'.$key.\'">\'.$value.\'</a></li>\';     
}
$block .= \'</ul></div>\';
print $block; 
}
add_action(\'a_z_pagination\', \'a_z_pagination\');
}
第行出现页面错误:“total”=>ceil($total\\u terms/$per\\u page)

<?php do_action(\'a_z_pagination\'); // A Z PAGINATION IS HERE!  ?>

<div class="content">
<?php
$per_page = \'1\';
$sortby = isset($_GET[\'sortby\']) ? $_GET[\'sortby\'] : null;
$page = ( get_query_var(\'paged\') ) ? get_query_var( \'paged\' ) : 1;
// number of tags to show per-page
$per_page = $number_of_performers ;
$offset = ( $page -1 ) * $per_page;
$args = array( \'orderby\' => $orderby,  \'number\' => $per_page,  
    \'offset\' => $offset,
    \'exclude\'       => array(), 
    \'exclude_tree\'  => array(), 
    \'include\'       => array(),
    \'fields\'        => \'all\', 
    \'hierarchical\'  => true, 
    \'child_of\'      => 0, 
    \'hide_empty\' => 0,
    \'pad_counts\'    => false,
    //\'terms\'     =>  $term->slug,
    \'cache_domain\'  => \'core\' );
$taxonomy = \'autor\';
$count_performers = wp_count_terms( $taxonomy, $offset );
$tax_terms = get_terms( $taxonomy, $args );
$total_terms = wp_count_terms( $taxonomy, $offset );
?>
<?php foreach ($tax_terms as $tag) : ?>
<?php 
$flag = 0; 
if( $sortby == substr( $tag->name, 0, 1 ) || $sortby==\'\' ) {    $flag = 1;} 
if ($flag==\'1\'){ // BELOW IS THE LAST POST IMAGE FROM TAX
?>
<div class="thumbs">

<a href="<?php echo get_term_link($tag->slug, \'autor\'); ?>" title="<?php echo $tag->name; ?>">  

<?php $args = 
 array (\'showposts\' => 1,\'orderby\' => \'rand\',\'order\' => \'DESC\',\'tax_query\' => array(
      array(\'taxonomy\' => \'autor\',\'field\'    => \'term_id\',\'terms\'    => $tag->term_id,),
   ),
);
$new_query = new WP_Query( $args ); if ( $new_query->have_posts() ) { while ( $new_query->have_posts() ) { $new_query->the_post();  $post_id = get_the_ID();
get_template_part( \'templates/image\', get_post_format() ); } 
} else {
} 
wp_reset_postdata(); 
?>

</a>

<p><?php echo $tag->name; ?></p>
<p><?php echo $tag->count;  _e(\'libros\', \'framework\'); ?></p>
</div>
</div>
<?php } ?>
<?php endforeach; ?>
<div class="clear"></div>
<?php
echo \'<div class="paginator lighter">\'; // NUMERIC PAGINATION IS HERE!
   $page_next = \'NEXT PAGE\'; $page_prev = \'PREVIOUS PAGE\';
   $big = 999999999; // need an unlikely integer
   if ( wp_is_mobile() ) { $ranger = $mid_size; } else { $ranger = \'3\'; }
   echo paginate_links( 
   array(
       \'base\'    => str_replace( $big, \'%#%\', esc_url( get_pagenum_link( $big ) ) ),
       \'format\'  => \'/page/%#%\',
        \'current\'       => max( 1, $paged ),
        \'prev_text\'     => $page_prev,
        \'next_text\'     => $page_next,
        \'show_all\'      => false,
        \'mid_size\' => $ranger,
        \'before_page_number\' => \'\',
        \'type\' => \'list\',
          \'after_page_number\' => \'\',
        \'total\'   => ceil($total_terms / $per_page )  // Error:  Warning: Division by zero
    ) 
 );
echo \'</div>\';
get_footer(); ?>

1 个回复
SO网友:David Sword

$per_page$number_of_performers, 该值必须不正确。

附言:你还可以减少$sort_array 定义为:

$sort_array = array();
$alphas = range(\'A\', \'Z\');
foreach ($alphas as $lttr)
   $sort_array[$lttr] = __($lttr,\'framework\');
<小时>

UPDATE

进一步@tom-j-nowell点$total_terms 存在问题-您的代码wp_count_terms()\'第二个论点应该是an array or a string query, 不是像这样的整数$offset

在进行故障排除时,查看数学和变量值可能会有所帮助,以便更好地了解问题所在。高于您的.paginator.lighter echo,我想补充一下:

echo "<pre>
total_terms = {$total_terms}\\n
per_page = {$per_page}\\n
---
total = ".($total_terms/$per_page)."</pre>";

结束

相关推荐

Pagination reset problem

我需要修复此网页。如果您想查看代码,请附上此页。当用户做出选择时,每个选项卡上的分页不会重置为1。这需要在他们单击选项卡时重置,如果要返回结果,分页显示为1。用户必须仍然能够通过url直接访问页面,即:http://thedemonsjumble.com/pcdev/archives/category/uncategorised/page/3/#latest有没有人对如何着手解决这个问题有什么想法。任何hep都将不胜感激。亲切的问候更改选项卡的链接:<div class=\"container\"&