wordpress - 查看单个帖子时显示子类别同级
感谢大家提供了一个很棒的网站。我学到了很多。我试图让我的子类别兄弟姐妹在单击单个帖子时显示。我已经使用 WordPress 菜单设置了我的父类别。我正在使用 php 小部件在单独的菜单中调用子类别(子类别)(然后使用 CSS 进行样式设置)。我使用的代码在单击每个类别时显示特定的(相关的)子项;但是我无法弄清楚如何让它们在查看帖子时出现。
<?php
如果(is_category()){
$breakpoint = 0;
$thiscat = get_term( get_query_var('cat') , 'category' );
$subcategories = get_terms( 'category' , 'parent='.get_query_var('cat') );
if(empty($subcategories) && $thiscat->parent != 0) {
$subcategories = get_terms( 'category' , 'parent='.$thiscat->parent.'' );
}
$items='';
if(!empty($subcategories)) {
foreach($subcategories as $subcat) {
if($thiscat->term_id == $subcat->term_id) $current = ' current-cat'; else $current = '';
$items .= '
<li class="cat-item cat-item-'.$subcat->term_id.$current.'">
<a href="'.get_category_link( $subcat->term_id ).'" title="'.$subcat->description.'">'.$subcat->name.'</a>
</li>';
}
echo "<ul>$items</ul>";
}
unset($subcategories,$subcat,$thiscat,$items);
} ?>
我试图模仿这个菜单 在先锋 Woman.com
任何帮助或更好的解决方案将不胜感激。 谢谢,
Thank you all for a great site. I'm learning a lot. I'm trying to get my subcategory siblings to show when a single post is clicked on. I have set up my parent categories using the wordpress menu. I am using a php widget to call for the children (subcategories) in a separate menu (and then style with CSS). The code I'm using is showing the specific (relevant) children when each category is clicked on; however I am unable to figure out how to make them appear when viewing a post.
<?php
if(is_category()) {
$breakpoint = 0;
$thiscat = get_term( get_query_var('cat') , 'category' );
$subcategories = get_terms( 'category' , 'parent='.get_query_var('cat') );
if(empty($subcategories) && $thiscat->parent != 0) {
$subcategories = get_terms( 'category' , 'parent='.$thiscat->parent.'' );
}
$items='';
if(!empty($subcategories)) {
foreach($subcategories as $subcat) {
if($thiscat->term_id == $subcat->term_id) $current = ' current-cat'; else $current = '';
$items .= '
<li class="cat-item cat-item-'.$subcat->term_id.$current.'">
<a href="'.get_category_link( $subcat->term_id ).'" title="'.$subcat->description.'">'.$subcat->name.'</a>
</li>';
}
echo "<ul>$items</ul>";
}
unset($subcategories,$subcat,$thiscat,$items);
}
?>
I'm attempting to mimic the behavior of this menu at pioneer woman.com
Any help or a better solution would greatly be appreciated.
Thanks,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这列出了当前帖子类别的所有子类别:
This lists all child categories of the current post's category: