我在我的子主题中的Woocommerce / archive-product-list.php中创建了我的产品类别模板,它采用列表格式。我已经分配了哪些商业产品类别将使用我的functions.php文件中的哪些模板。
我想添加 Previous&下一个类别链接到模板,该模板将动态创建下一个和上一个类别的URL,然后链接到相邻的woo商务类别和/或子类别,然后显示该类别中的列表项。
我发现很少有关于如何做到这一点的信息。大多数文章都属于同一类别中的上一篇/下一篇文章,而且不正在寻找的内容。
我发现的最接近的事情是2012年:
$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 '<div class="nav-previous"><a href="'.get_term_link( $categories[$prev_cat] ).'">Previous Category</a></div>'; echo '<div class="nav-next"><a href="'.get_term_link( $categories[$next_cat] ).'">Next Category</a></div>'; echo '<br><br>';
我已经阅读了一些关于分类和分页的讨论,但不知道这对我有什么帮助。即使它只是指向正确的方向,任何帮助都会非常感激。
谢谢。
答案 0 :(得分:0)
Below is the code from http://pastebin.com/0GG0HX4x adapted to work with a custom taxonomy (which is what WooCommerce's product category is).
I have NOT dug into this to ensure it lists them in the order you've described, the logic could get fairly complex to sort out issues around "is this a child? Does this have children? Which taxonomy should display next?" - which could also result in a fair amount more code, and potentially having to change strategies from the one used below. For some ideas of the options available for sorting, please refer to the documentation for get_terms(), particularly the orderby and order section.
Note also that the code below is untested, so please ask clarifying questions in the comments below and I will do my best to improve the code.
public void sendToTV(){
String myText = null;
TextView tv = (TextView) findViewById(R.id.noticeText);
EditText et = (EditText) findViewById(R.id.textView);
myText = et.getText.toString();
tv.setText(myText);
}