0

转到“mysite.com/category/my_city/restaurants/”,我可以显示“my_city”类别和“restaurants”类别下的所有帖子。

让我们假设餐厅类别有几个子类别(泰国菜、意大利菜等):我怎样才能列出所有子类别的餐厅的所有子类别,这些子类别也是并且仅在 my_city 类别下?

例如“mysite.com/category/my_city/thai/”

目前这是我的 category.php 文件中的代码:

<?php
$this_cat = (get_query_var('cat')) ? get_query_var('cat') : 1;
$this_category = get_category($this_cat);
if ( $this_category->parent ) { $this_cat = $this_category->parent; }
wp_list_categories('title_li=&child_of=' . $this_cat . '');
?>

结果是一个类似“泰国、意大利等”的列表(这显然很好),但链接都指向“mysite.com/category/restaurants/thai/”之类的东西,显示所有餐厅,不仅是那些在我的城市。显然我没有赶上其他类别,也不知道如何做正确的数组。

非常感谢您的帮助。

4

1 回答 1

0

https://gist.github.com/siddhartanaranjo/6073854

在此代码中,获取 cat-page 的 cat 并使用简单的 subcategory-loop 显示 subcats 和 parent

或在您的餐厅页面模板中

https://gist.github.com/siddhartanaranjo/6128695

于 2013-08-01T05:47:50.463 回答