WordPress.org

Ready to get started?Download WordPress

Forums

odd/even style to widget lists (4 posts)

  1. neologan
    Member
    Posted 4 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?

  2. stvwlf
    Member
    Posted 4 years ago #

    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.

  3. neologan
    Member
    Posted 4 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.

  4. neologan
    Member
    Posted 4 years ago #

    found the jQuery code myself. Thanks for the heads up, it does the job nicely.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.