Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Highlight current-cat style on single.php WordPress

  • SOLVED

Hi,

How can i highlight the current-cat style on the single.php file.
The CSS is already styled.

This is the code I used:

<?php wp_list_categories('title_li=&use_desc_for_title=0&hide_empty=0&exclude=100&current_category=1&child_of=76'); ?>


Take a look at the following link: http://www.aspbluesquare.be/referenties/bedrijfsevenementen/wella-trend-vision-award-2010/

It seems that WP doesn't take the current-cat style in its li style on the single.php file.
Can someone help me out. Thanks for the quick respons.

Answers (4)

2010-12-23

rilwis answers:

Replace your code with the following code:

<ul>
<?php

$html = wp_list_categories('title_li=&use_desc_for_title=0&hide_empty=0&exclude=95&child_of=74&current_category=0&echo=0');

$cats = wp_get_post_categories(get_the_ID());

foreach ($cats as $cat) {
$html = preg_replace("#cat-item-$cat#", '$0 curent-cat', $html);
}

echo $html;
?>
</ul>


This will add class="current-cat" to categories, which contains current post.


Filip Van Reeth comments:

Hi,

Does not work: http://www.aspbluesquare.be/referenties/bedrijfsevenementen/bedrijfsevenement-1/


rilwis comments:

I've tested at localhost, and worked. May I have your FTP account? I need to see why it doesn't work.

Send to my email: [email protected]


Filip Van Reeth comments:

Hi,

Here you are, but pls don't change anything. Just tell me what to change ;-)
I'm also on Skype filip4nono.

94.126.64.210
fk84cs4n
n4d9vb1p


rilwis comments:

Done for single_references_nl.php. The code I used above doesn't return correct array of current categories in your site. I really don't know why.

So I replaced with another code that works:

<ul>
<?php
$html = wp_list_categories('title_li=&hide_empty=0&exclude=95&child_of=74&echo=0');
foreach((get_the_category()) as $category) {
$cat = $category->cat_ID;
$html = preg_replace("#cat-item-$cat#", '$0 curent-cat', $html);
}
echo $html;
?>
</ul>


Filip Van Reeth comments:

Nopes,

Pasted it but does not work.


rilwis comments:

Opps! I made a syntax mistake: "curent-cat" instead of "current-cat" :D

Just fixed it. Plz take a look.


Filip Van Reeth comments:

Hi,

Current cats works on references but not on nieuws:
<ul>
<?php
$html = wp_list_categories('title_li=&hide_empty=1&child_of=1&echo=0');
foreach((get_the_category()) as $category) {
$cat = $category->cat_ID;
$html = preg_replace("#cat-item-$cat#", '$0 current-cat', $html);
}
echo $html;
?>
</ul>


Link: http://www.aspbluesquare.be/nieuws/asp-blue-squares-totaalleverancier-voor-evenementiele-sector/

2010-12-23

Rashad Aliyev answers:

do you mean about "REFERENTIES" ?


Rashad Aliyev comments:

It's seems highlighted now. That's H1


h1 {
background-image: url(http://www.aspbluesquare.be/wp-content/themes/aspbs-v2/img/snav-title-xmas.png);
color: white;
font-family: museo-slab-1, museo-slab-2, serif;
font-size: 18px;
height: 31px;
margin-bottom: 5px;
margin-left: -5px;
margin: 0px 0px 5px -5px;
padding: 10px 0px 0px 13px;
padding-left: 13px;
padding-top: 10px;
text-transform: uppercase;
width: 230px;
}


Filip Van Reeth comments:

It has to used for every part References, news, links, contact, ...
It's weird that WP doesn't take the current-cat style.

2010-12-23

Ehthisham tk answers:

use this a great plugin
<strong>[[LINK href="http://kahi.cz/wordpress/highlight-used-categories-plugin/"]]http://kahi.cz/wordpress/highlight-used-categories-plugin/[[/LINK]]</strong>

add a .used-cat class in your style.css to behave similarly as the .current-cat class

or are u lookin for this ↓
<?php
$catsy = get_the_category();
$myCat = $catsy[0]->cat_ID
?>


Filip Van Reeth comments:

How do i add this into the code:
<ul>

<?php wp_list_categories('title_li=&use_desc_for_title=0&hide_empty=0&exclude=95&child_of=74&current_category=0'); ?>
</ul>

2010-12-23

Sébastien | French WordpressDesigner answers:

<?php
$catsy = get_the_category();
$myCat = $catsy[0]->cat_ID;
$currentcategory = '&current_category='.$myCat;

wp_list_categories('hierarchical=1&use_desc_for_title=0&exclude=12&depth=1&orderby=id&title_li='.$currentcategory);
?>


and, so, in your case :
<?php
$catsy = get_the_category();
$myCat = $catsy[0]->cat_ID;
$currentcategory = '&current_category='.$myCat;

wp_list_categories('title_li=&use_desc_for_title=0&hide_empty=0&exclude=100'.$currentcategory'&child_of=76');
?>


Filip Van Reeth comments:

gives a white page ;-(

;-)


Sébastien | French WordpressDesigner comments:

nooo ?! Paste all your code, you have probably an error in your code.