我想在woocommerce模板的类别存档页面中显示上一个类别和下一个类别链接。我从另一篇文章中获得了这段代码,但对我来说,错误即将来临。这些是错误,
可捕获的致命错误:类WP\\u error的对象无法转换为[文件]中的字符串,并且未定义$next\\u cat和$prev\\u cat的变量
$this_category = get_queried_object();
$categories = get_categories();
foreach( $categories as $position => $cat ) :
if( $this_category->term_id == $cat->term_id ) :
$next_cat = $position + 1;
$prev_cat = $position - 1;
break;
endif;
endforeach;
$next_cat = $next_cat == count($categories) ? 0 : $next_cat;
$prev_cat = $prev_cat < 0 ? count($categories) - 1 : $prev_cat;
echo \'previous: \' . get_term_link( $categories[$prev_cat] );
echo \'next: \' . get_term_link( $categories[$next_cat] );
非常感谢您的帮助。