WordPress.org

Support

Support » Plugins and Hacks » Hacks » index of current widget in sidebar

index of current widget in sidebar

  • hello

    i wonder if i had some opportunity to check using PHP index of position of widget in sidebar.

    i am going to create some widget (i think i will do this with help of this tutorial http://www.lonewolfdesigns.co.uk/create-wordpress-widgets/). this widget will show number, same as position of widget in sidebar. how to get this number?

    if it is still unclear:

    imagine that somebady has widgetized sidebar on his blog. he put there few diffrent widgets and one is mine. this widget have to show message “hello, i am widget number 4 in this sidebar” (if widget will be placed as fourth, otherwise number will be difffrent)

    any idea? thank you in advance for any suggestions 🙂

Viewing 1 replies (of 1 total)
  • You can hook into ‘dynamic_sidebar’ action, which runs every time before widget is being viewed in front-end. It can be for example just a function with an incrementing global variable (if you don’t hate them too much :)).

    Assuming there might be more than one sidebar, you’ll also need to reset the counter. You can possibly use ‘sidebars_widgets’ action hook for that.

Viewing 1 replies (of 1 total)
  • The topic ‘index of current widget in sidebar’ is closed to new replies.
Skip to toolbar