在我的电影wordpress主题中创建了一个不错的功能,其中有一个名为“ actor”的自定义分类法。我在自定义页面模板上列出了所有actor,并且在分页时一切正常。
我正在尝试添加后一个分页菜单,但是我在此处添加了堆栈,我想在这里找到开发人员的任何答案。
我的 template-actors.php 模板:
<?php
/*
Template Name: Template Actors
*/
get_header();
$number = 30; // number of terms to display per page
//Dynamic url
$orderby = isset($_GET['orderby']) ? $_GET['orderby'] : null;
//Taxonomy setup starts here
$taxonomy = 'actor';
$page = ( get_query_var('paged') ) ? get_query_var( 'paged' ) : 1;
$offset = ( $page > 0 ) ? $number * ( $page - 1 ) : 1;
//Total terms to setup the pagination.
$totalterms = wp_count_terms( $taxonomy, array( 'hide_empty' => true ) );
$totalpages = ceil( $totalterms / $number );
$args = array(
'order' => 'ASC',
'hide_empty' => true,
'exclude' => array(),
'exclude_tree' => array(),
'include' => array(),
'number' => $number,
//'fields' => 'all',
'slug' => '',
'parent' => '',
'hierarchical' => true,
'child_of' => 0,
'get' => '',
'name__like' => '',
'pad_counts' => false,
'offset' => $offset,
'search' => '',
'cache_domain' => 'core'
);
$tax_terms = get_terms( $taxonomy, $args );
//Taxonomy setup ends here
?>
<div class="container">
<div class="row">
<div class="col-md-12">
<div class="heading pull-left">
<?php the_title(); ?>
</div>
<?php
do_action('letters_menu'); //Display the letter menu
?>
<div class="clearfix"></div>
<div id="actor-list" class="list-view">
<div id="actor-thumbs" class="actor-listing clearfix">
<div class="items">
<?php
foreach ($tax_terms as $actor) : ?>
<?php
$flag = 0;
if( $orderby == substr( $actor->name, 0, 1 ) || $orderby=='' ) {
$flag = 1;
}
?>
<?php
if ( $flag == '1' ) {
?>
<div class="actor-item">
<span class="actor-name"><?php echo $actor->name; ?></span>
</div>
<?php } ?>
<?php endforeach; ?>
</div>
</div>
</div>
<?php
//Show custom page navigation
printf( '<nav class="pager">%s</nav>',
taxonomy_pagination( $totalpages, $page, 3, 0 )
);
?>
</div>
</div>
</div>
<?php get_footer(); ?>
该模板中包含的功能是:
if( !function_exists('letters_menu') ) {
function letters_menu() {
$order = isset( $_REQUEST['orderby'] ) ? trim($_REQUEST['orderby']) : 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')
);
$block = '';
$block = '<ul class="letters-menu">';
foreach ( $sort_array as $key=>$value ){
$active = ( $order == $key ) ? 'active' : null;
$block .= '<li><a class="'.$active.'" href="'.get_permalink().'?orderby='.$key.'">'.$value.'</a></li>';
}
$block .= '</ul>';
print $block;
}
add_action('letters_menu', 'letters_menu');
}
function taxonomy_pagination( $totalpages, $page, $end_size, $mid_size ) {
global $awpt;
$page_next = 'Nex Page';
$page_prev = 'Previous Page';
$bignum = 999999999;
if ( $totalpages <= 1 || $page > $totalpages ) return;
return paginate_links( array(
'base' => str_replace( $bignum, '%#%', esc_url( get_pagenum_link( $bignum ) ) ),
'format' => '',
'current' => max( 1, $page ),
'showall' => false,
'total' => $totalpages,
'prev_text' => $page_prev,
'next_text' => $page_next,
'show_all' => false,
'end_size' => $end_size,
'mid_size' => $mid_size
) );
}
菜单网址结构的一个示例是:
localhost/wordpress/actor-list/?orderby=A
localhost/wordpress/actor-list/?orderby=B
localhost/wordpress/actor-list/?orderby=C
1。问题::如果我有多个以字母A开头的演员,则仅显示一个词,而不是全部。
2。问题:如何将字母菜单集成到分类法分页中?因为当我跳到任何字母时,它都会显示以下所有术语的分页。
我考虑过add_query_var,并检查了许多有关此问题的帖子,但在这里无法正常工作。也许我必须在 $ totalterms 中添加一些内容?还是可能最好的问题是,有没有办法在没有任何术语的字母上添加禁用类?