• Resolved Aruz

    (@aruz)


    How can I get “widget id number” in the widget ready sidebar for my new theme which I mading?
    Thanks for your time..

Viewing 13 replies - 1 through 13 (of 13 total)
  • look in the HTML for the LI tag start of the widget. you should see stuff like:

    <li id=”get-recent-comments” class=”widget widget_get_recent_comments”>

    guess what the ID of this widget is? 😀

    Thread Starter Aruz

    (@aruz)

    🙂 for example you can see this in admin panel.

    You are using the Default theme with 6 widgets.

    I need the these 6 widgets Id number.
    All I need like this.
    <li id="get_recent_comments" class="widget 4">...</li>

    Thread Starter Aruz

    (@aruz)

    Anyone?

    They don’t have numeric IDs, they have “classes” as names – as the example given is showing.

    Thread Starter Aruz

    (@aruz)

    Ben şimdi sayardım da… Ok guys. Thanks for your help. I hope the developpers give numeric IDs to them for the new version of wp. This will be a design revolution. The World will be change…

    Moderator Samuel Wood (Otto)

    (@otto42)

    WordPress.org Admin

    Why, exactly, do you want them to have numeric ID’s? They already have unique ID’s and classes, they don’t need numeric ID’s for anything.

    You’re not making any sense. Explain what you want to do, let us tell you how you should be doing it.

    Thread Starter Aruz

    (@aruz)

    I wanna make different colored sidebar widgets, but widget ready.
    Like comments’ background colors of default theme. Forexample first widget’s background color will be grey, second white, third grey…
    If widgets not ready this is easy but widget ready.

    you might be able to do this sort of thing with CSS in modern browsers

    UL#sidebar > LI:first-child { background-color: XXX}
    UL#sidebar > LI:first-child + LI { background-color: YYY}
    UL#sidebar > LI:first-child + LI + LI { background-color: ZZZ}

    (er i’m not 100% sure about my syntax there). or in desperation use JS in the page footer to play with the DOM, something like

    x=document.getElementById(‘sidebar’).getElementsByTagName(‘li’);
    for(i=0;i< x.length;i++)
    { x[i].classname=”widget-color-“.i; }

    (again just making this up on the fly – not tested code!) to give consecutive widgets the class “widget-color-0” “widget-color-1” etc

    Moderator Samuel Wood (Otto)

    (@otto42)

    WordPress.org Admin

    I still don’t quite see the problem. If your widgets are defined properly in the theme’s functions.php file (similar to 'before_widget' => '<li id="%1$s" class="widget %2$s">'), then every widget gets a unique ID. Just reference them by that ID and give them the colors you want them to have.

    Just reference them by that ID and give them the colors you want them to have.

    He could do that if it’s his theme and his installation.
    But let’s say that you design a theme and you dont know what widgets will be used. All you want is assign them an extra class ID, different in each one.

    All you got is –> li id=”%1$s” class=”widget %2$s”

    But you cannot add any php variable like an increasing number or a random number there (or at least i haven’t find a way yet).

    But i’ll try alanft JS code, he may have a point!

    Moderator Samuel Wood (Otto)

    (@otto42)

    WordPress.org Admin

    If you’re pretty good with writing filters, you could hook into the dynamic_sidebar_params filter. You’ll get the params of each widget just before it’s written. If you examine the before_widget bit of that, you’ll find the id and class in there. Add what you like to them at that point. Simplest way would be to include your own class piece and string replace it with your counter stuff.

    If you’re doing this in a theme, put your code into the functions.php file and bundle it with the theme.

    Thx a lot Otto for your advice.
    I ll sure give it a try 🙂

    Thread Starter Aruz

    (@aruz)

    Thanks a lot. But this is complex for me. Thanks for your time.

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘How ca I get “widget id”?’ is closed to new replies.