我已经为我购买的主题创建了一个子主题。购买的主题是为想要展示菜单的餐厅设计的。主题接受菜单项作为帖子,并根据类别对其进行分组。该主题只接受1级类别,而不接受具有2级类别的更复杂菜单。
购买的主题是为1级层次结构构建的。e、 g:
>Menu
>>>Breakfast
>>>Lunch
>>>Dinner
然而,我工作的餐厅有一个更复杂的菜单:
>Menu
>>>Breakfast
>>>>>>Food
>>>>>>Sides
>>>>>>Drinks
>>>Lunch
>>>>>>Small
>>>>>>Large
>>>>>>Sides
“我的孩子”主题旨在支持两个级别的类别。
以下是可能给我带来问题的代码部分:
<?php $args=array(
\'orderby\' => \'slug\',
\'order\' => \'ASC\',
\'include\' => \'4, 5, 6, 27\',
//\'exclude\' => \'3, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26\',
\'child_of\' => $menuCat
);
$categories=get_categories($args);
foreach($categories as $category) {
$catName = $category->name;
$catName = strtolower($catName);
$catName = str_replace (" ", "", $catName);
$catName = str_replace ("&", "", $catName);
$catName = str_replace ("é", "e", $catName);
?>
<div class="menuSection section" id="<?php echo $catName; ?>">
<div class="titles"><h2><?php echo $category->name; ?></h2></div>
<?php if($category->description){ ?>
<p class="catDescription"><?php echo $category->description; ?></p>
<?php } ?>
<?php $args=array(
\'orderby\' => \'slug\',
\'order\' => \'ASC\',
\'parent\' => $category->term_id
);
$subcategories=get_categories($args);
foreach($subcategories as $subcategory) {
$showPostsInSubCategory = new WP_Query();
$showPostsInSubCategory->query(\'cat=\'.$subcategory->term_id.\'&showposts=100\');
?>
...loop through display of subcategory
我的
child theme 尝试支持两个级别的类别。
Here 是原始主题的索引。php。
尽管我已经硬编码了要包括哪些类别,the website 仅显示1个类别(午餐)的帖子。
Why is Lunch the only category being displayed?
最合适的回答,由SO网友:Krzysiek Dróżdż 整理而成
我在本地的WordPress上玩了一下你的代码。我想这应该能解决你的问题。
你的第一个论点get_categories
呼叫,应如下所示:
$args=array(
\'hide_empty\'=>false,
\'orderby\' => \'slug\',
\'order\' => \'ASC\',
//\'include\' => \'5, 6, 7, 8\', - you don\'t need to include anything
//\'exclude\' => \'3, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26\', - no need to exclude anything either
\'parent\' => $menuCat
);
对于第二个:
$args=array(
\'hide_empty\' => false,
\'orderby\' => \'slug\',
\'order\' => \'ASC\',
\'parent\' => $category->term_id
);
它在我的WP上正常工作。
我还建议使用<h3>
标记以显示子类别。