Wordpress Themes - WP Forum at BFA

Wordpress Themes - WP Forum at BFA (http://forum.bytesforall.com/index.php)
-   Page & Category Menu Bars (http://forum.bytesforall.com/forumdisplay.php?f=10)
-   -   Category description & category classes (http://forum.bytesforall.com/showthread.php?t=867)

shedhed Mar 19, 2009 02:52 PM

Category description & category classes
 
I'm trying to modify the category horizontal menu to do two things:-

Firstly to incorporate the category description under the actual category. I appreciate that this is available as a "hover" option but I'm trying to show it permanently.

Secondly I'm looking to limit the categories to 5 of my choice through the theme options (done), set them to 20% width (done) and style their colours/hover colours individually. To do this last bit I think I need individual li classes on each category so that I can style them one by one. Only the current li gets a class.

I've mooched about where this code is generated and I think it's in bfa_hor_cats.php - here's an example:-

Code:

$list_cat_string = preg_replace("/<li class=\"(cat-item|cat-item cat-item-[0-9]+)(.*?)\n<ul class='children'>/i","<li class=\"rMenu-expand\\2\n <ul class=\"rMenu-ver\">",$list_cat_string);
Now using shedhed's law of tinkering with code when you have no idea what you're doing I eventually got round to removing the pipe symbol thus:-

Code:

$list_cat_string = preg_replace("/<li class=\"(cat-item cat-item cat-item-[0-9]+)(.*?)\n<ul class='children'>/i","<li class=\"rMenu-expand\\2\n <ul class=\"rMenu-ver\">",$list_cat_string);
This ends up with with the category li's having a class, eg:-

HTML Code:

<li class="cat-item cat-item-13"><a title="blah." href="http://blah/wordpress/category/blah/">Blah blah</a>
</li>

By doing this have I broken something that I don't know about - I'm a complete php novice and lethal with it. If I have is there a way to get classes on each category?

Any help with either of the above gratefully received.

Thanks, Andy

Flynn Mar 20, 2009 04:01 PM

What you did will be the standard from version 3.2.1 on - I am adding back all extra classes that Wordpress adds throughout a site, and even add some more

I had removed some of the default classes/IDs as they weren't used by Atahualpa but I realized that having classes and an ID on just about any element easily outweighs the disadvantage of a more cluttered code

shedhed Mar 21, 2009 02:51 PM

Flynn,

Thanks for your reply - appreciated.

Having all those classes available in the next issue will be good news.

Do you have any guidance on how to add the category description to the horizontal category menu bar? I'm trying to get the description to appear beneath its menu item permanently rather than rely on the hover.

Thanks in advance,

Andy

Flynn Mar 21, 2009 03:35 PM

In functions/bfa_hor_cats.php change

PHP Code:

if ($titles == "No") { $list_cat_string reg_replace("/title=\"(.*?)\"/i","",$list_cat_string);}
return 
$list_cat_string;
}
?> 

to

PHP Code:

$list_cat_string = preg_replace_callback("|title=\"(.*?)\">(.*?)</a>|","add_title_to_anchor",$list_cat_string);
if ($titles == "No") { $list_cat_string = reg_replace("/title=\"(.*?)\"/i","",$list_cat_string);}
return $list_cat_string;
}
?>
<?php
function add_title_to_anchor($matches) {
return 
'>'.$matches[2].'<br /><span class="cat-descr">'.$matches[1].'</span></a>';
}
?>

And at A. Theme Options -> HTML/CSS Inserts -> CSS Inserts add something like this

HTML Code:

span.cat-descr {
text-transform: none;
font-size: 90%;
color: #dddddd;
}

to style the description text, i.e. make the font smaller and don't capitalize the words (as Atahualpa does with Page and Category names in menu bars, in its default setting)

if you haven't set a description for a category (at Site Admin -> Categories -> Edit -> Description) then the text will be "View all posts filed under [Category Name]". To show the description only if a description was set, and otherwise display nothing instead of "View all posts....", replace the last part in the code above, this one

PHP Code:

 <?php
function add_title_to_anchor($matches) {
return 
'>'.$matches[2].'<br /><span class="cat-descr">'.$matches[1].'</span></a>';
}
?>

with this one:

PHP Code:

 <?php
function add_title_to_anchor($matches) {
if (
strpos($matches[1],'View all posts filed under')!==FALSE) {
return 
'>'.$matches[2].'</a>';
} else {
return 
'>'.$matches[2].'<br /><span class="cat-descr">'.$matches[1].'</span></a>';
}
}
?>


shedhed Mar 22, 2009 01:25 AM

Flynn,

Brilliant - exactly what I was after. Thank you.


Andy


All times are GMT -6. The time now is 05:44 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.