I’m busy with this WordPress website: https://tftinstallatie.inpointbox.nl/producten/systeemplafondarmaturen/test-02/
The link (above) shows a post. It’s a product, which I have made with custom post types. At the left you see al the product cats, created with a taxomony.
That works realy nice. On the archive page the menu shows correct the active taxomony with “current_cat”. But when you’re on a product, the current taxomony don’t get a “current_cat” class.
How can I fix this, so that the menu get also a current class when the product is showing.
This is the code to list the taxomony list.
<?php
$taxonomy = 'productcats';
$orderby = 'name';
$show_count = 1; // 1 for yes, 0 for no
$pad_counts = 0; // 1 for yes, 0 for no
$hierarchical = 1; // 1 for yes, 0 for no
$title = 'Productcategoriën:';
$args = array(
'taxonomy' => $taxonomy,
'orderby' => $orderby,
'show_count' => $show_count,
'pad_counts' => $pad_counts,
'hierarchical' => $hierarchical,
'title_li' => $title
);
?>
Thanks in advance!
Derk
]]><?php
$cat_id = get_cat_ID('All'); //put your category here
wp_list_categories('title_li=&taxonomy=categories¤t_category=' .$cat_id);
?>
And is not working but if i remove taxonomy=categories the problem is solved but i only want to list the categories in my taxonomy is there any way to fix that?
Thank’s
]]>$top_level_cats = get_categories(‘child_of=0&parent=0’);
assuming that 0 is the ID of the top. This does not work.
End goal is to find out if the current category is the child of a top level category.
Thanks.
]]>Here is my current code:
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<?php
// check if the post belongs directly to the current category;
// continue if not
$current_categories = get_the_category();
$found_category = false;
foreach ($current_categories as $current_category) {
if ($current_category->term_id == $cat) {
$found_category = true;
// counting level
$level = 0;
while ($current_category->parent != 0) {
$current_category = get_category($current_category->parent);
$level = $level + 1;
}
break;
}
}
if (!$found_category) {
continue;
}
?>
Additionally i have two releated issues to that children content one.
1.) i use MyCategoryOrder Plugin, to sort the categories and i wuld like for the display of the content, to keep the same order/structure:
<?php wp_list_categories('orderby=order&show_count=0&title_li=&depth=3'); ?>
2.) by clicking on the parent category, my navigation menu starts displaying the children. Can i somehow mark the first children (which content should be displayed) with a “current_cat” css-class? So that the users know where he/she is?
Thank You for your support in advance,
bb
Basically in my CSS the current_cat and current_page_items are highlighted in the same way.
I noticed that when viewing a page, the correct menu item was highlighted. But when I viewed a category page both the category item and the page item were classed as current.
i.e. when viewing index.php?cat=5 both category 5 and page-id 5 were classed as current.
The solution is to edit the wp_includes/classes.php file. Look for:
function start_el($output, $page, $depth, $current_page, $args) {
if ( $depth )
$indent = str_repeat("t", $depth);
extract($args);
$css_class = 'page_item';
$_current_page = get_page( $current_page );
if ($page->ID == $current_page )
$css_class .= ' current_page_item';
...
you need to replace the line
if ($page->ID == $current_page )
with
if (is_page() && $page->ID == $current_page )
and that should do it.