我想按字母顺序列出分类法。我发现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(); ?>