neologan
Member
Posted 3 years ago #
I'd like to achieve adding a class to each li elements from within a widget, like this:
<div id="categories-3" class="widget widget_categories"><h3>Categories</h3>
<ul>
<li class="cat-item cat-item-13 odd">list element 1</li>
<li class="cat-item cat-item-13 even">list element 2</li>
<li class="cat-item cat-item-13 odd">list element 3</li>
<li class="cat-item cat-item-13 even">list element 4</li>
</ul>
Odd / even being what i want to do.
Does anyone know how this can be done?
Not sure if you can do that within a widget. It could be done easily adding a few lines of jQuery (javascript) code to the theme header. Is that approach acceptable to you? If so I'll show you the code.
neologan
Member
Posted 3 years ago #
i would certainly like to know the jquery way if it's not too resource hungry.
But there must be a way. If the li elements already have a class, which they do, surely there must be a filter that can be used for this, a bit like how this was achieved(?):
http://wordpress.org/support/topic/206194?replies=5#post-957593
Anyhow, would love to know the jquery method just so it solves the problems for now.
neologan
Member
Posted 3 years ago #
found the jQuery code myself. Thanks for the heads up, it does the job nicely.