我正在使用无限卷轴和以下伟大的代码from here 在术语循环中生成下一个分类术语链接。当您到达当前类别的末尾时,我想添加下一个Woocommerce产品类别。
一切正常,只是只加载了一个术语,然后它说;没有其他要显示的项目;。甚至浏览器url也会根据滚动定位的术语而变化。你知道这样做是否可行吗?
下一个/上一个术语链接代码:
function get_tax_navigation( $taxonomy = \'category\', $direction = \'\' )
{
// Make sure we are on a taxonomy term/category/tag archive page, if not, bail
if ( \'category\' === $taxonomy ) {
if ( !is_category() )
return false;
} elseif ( \'post_tag\' === $taxonomy ) {
if ( !is_tag() )
return false;
} else {
if ( !is_tax( $taxonomy ) )
return false;
}
// Make sure the taxonomy is valid and sanitize the taxonomy
if ( \'category\' !== $taxonomy
|| \'post_tag\' !== $taxonomy
) {
$taxonomy = filter_var( $taxonomy, FILTER_SANITIZE_STRING );
if ( !$taxonomy )
return false;
if ( !taxonomy_exists( $taxonomy ) )
return false;
}
// Get the current term object
$current_term = get_term( $GLOBALS[\'wp_the_query\']->get_queried_object() );
// Get all the terms ordered by slug
$terms = get_terms( $taxonomy, [\'orderby\' => \'slug\'] );
// Make sure we have terms before we continue
if ( !$terms )
return false;
// Because empty terms stuffs around with array keys, lets reset them
$terms = array_values( $terms );
// Lets get all the term id\'s from the array of term objects
$term_ids = wp_list_pluck( $terms, \'term_id\' );
/**
* We now need to locate the position of the current term amongs the $term_ids array. \\
* This way, we can now know which terms are adjacent to the current one
*/
$current_term_position = array_search( $current_term->term_id, $term_ids );
// Set default variables to hold the next and previous terms
$previous_term = \'\';
$next_term = \'\';
// Get the previous term
if ( \'previous\' === $direction
|| !$direction
) {
if ( 0 === $current_term_position ) {
$previous_term = $terms[intval( count( $term_ids ) - 1 )];
} else {
$previous_term = $terms[$current_term_position - 1];
}
}
// Get the next term
if ( \'next\' === $direction
|| !$direction
) {
if ( intval( count( $term_ids ) - 1 ) === $current_term_position ) {
$next_term = $terms[0];
} else {
$next_term = $terms[$current_term_position + 1];
}
}
$link = [];
// Build the links
if ( $previous_term )
$link[] = \'<div class="tax-pages"> <a class="prev" href="\' . esc_url( get_term_link( $previous_term ) ) . \'">\' . $previous_term->name . \'</a></div>\';
if ( $next_term )
$link[] = \'<div class="tax-pages"> <a class="next" href="\' . esc_url( get_term_link( $next_term ) ) . \'">\' . $next_term->name . \'</a></div>\';
return implode( \' ...|... \', $link );
}
无限滚动代码
$(\'#main\').infiniteScroll({
path: ".tax-pages a.next",
hideNav: ".tax-pages",
append: "#main ul.products",
status: \'.page-load-status\'
});