adding variable/array to script (3 posts)

  1. nicnack
    Posted 2 years ago #


    Below is a script that creates a widget area. Any widget that is added into this area is contained within a simple <div></div> tag.

    I need the script to generate a unique ID per div (widget) created.. so that it would be like:
    <div id="name1">widget 1 here</div>
    <div id="name2">next widget here</div>
    <div id="name1">another widget here</div>

    here is the script:

    function arphabet_widgets_init() {

    register_sidebar( array(
    'name' => 'Home Footer',
    'id' => 'home_bottom_1',
    'before_widget' => '<div>',
    'after_widget' => '</div>',
    'before_title' => '<h2 class="rounded">',
    'after_title' => '</h2>',
    ) );
    add_action( 'widgets_init', 'arphabet_widgets_init' );

    any suggestions?

  2. bcworkz
    Posted 2 years ago #

    The 'before_widget' string gets fed as a format specifier into a sprintf() function when the widget is output, with the data arguments being the widget ID and class name. To get output similar to "<div id=\"$widget_id\""> use the following array value assignment: 'before_widget' => '<div id="%1$s">',

    The widget ID will be a unique string representation of an integer, it will not be name1, name2 etc.

  3. nicnack
    Posted 2 years ago #

    ok great ill try it out.. thanks so much!

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.