Many thanks!
]]>I’m running out of patients on this. Does anyone know of a simple way to highlight multiple categories in a list on single.php?
My current code only brings up a single category, it uses wp_list_categories, intended for archive pages i know. Strange that there is not yet a function for the single post template. Or is there?
<?php $catsy = get_the_category();
$myCat = $catsy[0]->cat_ID;
wp_list_categories(array(
'title_li' => '',
//ONE AT A TIME PLEASE 0_0
'current_category' => $myCat ?>
It shouldn’t have to be a massive hack.
Here’s one of the posts with only one category showing:
https://www.purkiss-archive.eu/hambling-maggi/
There should be two.
I was able to do the trick for Categories/Single Posts, with this:
// Filter to add the "current-cat" class to categories list in Single Post (https://www.transformationpowertools.com/wordpress/highlight-post-categories-function/2)
// --------------------------------------------------------------------
add_filter('wp_list_categories','style_current_cat_single_post', 10, 2);
function style_current_cat_single_post($output) {
if(is_singular()):
global $post;
$categories = wp_get_post_categories($post->ID);
foreach($categories as $value) {
if(preg_match('#item-' . $value . '">#', $output)) {
$output = str_replace('item-' . $value . '">', 'item-' . $value . ' current-cat">', $output);
}
}
endif;
return $output;
}
I’d like to do the same for Taxonomies/Custom Post Types, and I am close with this:
add_filter('wp_list_categories', 'sgr_show_current_cat_on_single', 10, 2);
function sgr_show_current_cat_on_single($output, $args) {
if (is_single()) :
global $post;
$terms = get_the_terms($post->ID, $args['shop-categories']);
foreach($terms as $term) {
if (preg_match('#cat-item-' . $term ->term_id . '#', $output)) {
$output = str_replace('cat-item-'.$term ->term_id, 'cat-item-'.$term ->term_id . ' current-cat', $output);
}
}
endif;
return $output;
}
But that highlights ALL the terms from the list.
By the way, I get the list from this:
<ul id="sub-nav">
<?php wp_list_categories('title_li=&taxonomy=shop-categories'); ?>
</ul>
Anyone knows the trick?
]]>Wassup? I tried to find the solution of my problem but I can’t find it anywhere… I hope someone will be a wordpress master to help me
here is my problem:
I have a custom post type called “produits” using taxonomy for this post type called “filtres”. To display the taxonomy list I use this code:
$orderby = 'name';
$show_count = 0; // 1 for yes, 0 for no
$pad_counts = 0; // 1 for yes, 0 for no
$hierarchical = 1; // 1 for yes, 0 for no
$taxonomy = 'filtres';
$title = '';
$args = array(
'orderby' => $orderby,
'show_count' => $show_count,
'pad_counts' => $pad_counts,
'hierarchical' => $hierarchical,
'taxonomy' => $taxonomy,
'title_li' => $title
);
?>
<?php
wp_list_categories($args);
?>
Everything works fine! I need to highlight the current-cat so I used the CSS to do that and it works! Going in the taxonomy, highlighting work too ! The problem is when I visit a single post of my post type, the current-cat doesn’t appear in the <li > < /li>
Does anyone know how to add the “current-cat” class to my wp_list_categories in a single post type?
Thanks a lot guys, you’ll make my day !
BTW HAPPY NEW YEAR !
]]><?php wp_list_categories( array (
'taxonomy' => 'uniquetaxonomy',
'current_category' => 1,
'title_li' => ''
)); ?>
I’ve failed to find a solution online, I’m hoping someone might have a work around for this.
Cheers
]]>https://www.leapfrogwebmarketing.com/clients/creative_expression/archives/category/events
<div id="breadcrumbs">
<?php
$catsy = get_the_category();
$myCat = $catsy[0]->cat_ID;
if(in_category($myCat)) {
?>
<?php wp_list_categories('child_of=$catsy&orderby=order&title_li=¤t_category='.$myCat'); ?>
<?php } ?>
</div> <!-- end #breadcrumbs -->
Thanks,
Terence
https://www.leapfrogwebmarketing.com/clients/creative_expression/archives/category/events
<div id="breadcrumbs">
<?php
$catsy = get_the_category();
$myCat = $catsy[0]->cat_ID;
if(in_category($myCat)) {
?>
<?php wp_list_categories('child_of=$catsy&orderby=order&title_li=¤t_category='.$myCat'); ?>
<?php } ?>
</div> <!-- end #breadcrumbs -->
Thanks,
Terence
I have created a custom post type called “prodotti” and a taxonomy called ‘categorie’.
Now when I retrieve in the taxonomy archive page (taxonomy-categorie.php) the category listing it works perfectly but it doesn’t display at all the “current-cat” class.
My code in functions .php
[Code moderated as per the Forum Rules. Please use the pastebin]
Anyone can help? Thanks in advance.
]]>(Don’t bother asking why I need it to be something else. It’s a long story. )
]]>