• Hello, I am looking to give each of my widgets a unique identifer in two places, I have capitalized below where im looking for the identifiers if anyone could help please. Thanks

    // Register Sidebars
    register_sidebar( array(
              'name' => 'Primary Sidebar',
              'before_widget' => "<div class=\"xoxo2\">",
              'before_title' => "<div class=\"widgettitle\"><div style=\"float:right;display:inline\"><a href=\"javascript:animatedcollapse.toggle('UNIQUEIDPLEASE')\"><img src=\"http://blablabla/intranetfront/wp-content/themes/whiteboard/images/downarrow.jpg\"></a></div>",
              'after_title' => '</div><div id="SAMEUNIQUEIDASABOVEPLEASE:-)" class="widgetcontent"><div  class="textwidget">',
              'after_widget' => '</div></div></div>'
    ) );
Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter huntz

    (@huntz)

    Ok I see how to do that but I try to use the same piece of code to put in the second place i’m looking for the id and it doesn’t work. Any ideas?

    Thanks

    Thread Starter huntz

    (@huntz)

    I use id=”%1$s” in ‘before_widget’ and it works but it doesn’t work in after_title. That %1$s only works in ‘before_widget’ by the looks of it. Could I store it in a var or something?

    Ok, so assuming you want to register several and have incrementing IDs, a basic counter..

    <?php
    $i = 1; // i is 1
    register_sidebar( array(
    	'name' => "My sidebar $i",
    	'before_widget' => "<div class=\"xoxo2\">",
    	'after_widget' => "</div></div></div>",
    	'before_title' => "<div class=\"widgettitle\"><div style=\"float:right;display:inline\"><a href=\"javascript:animatedcollapse.toggle('my-sidebar-$i')\"><img src=\"http://blablabla/intranetfront/wp-content/themes/whiteboard/images/downarrow.jpg\"></a></div>",
    	'after_title' => "</div><div id=\"my-sidebar-$i\" class=\"widgetcontent\"><div class=\"textwidget\">"
    ));
    $i++; // i is now 2
    register_sidebar( array(
    	'name' => "My sidebar $i",
    	'before_widget' => "<div class=\"xoxo2\">",
    	'after_widget' => "</div></div></div>",
    	'before_title' => "<div class=\"widgettitle\"><div style=\"float:right;display:inline\"><a href=\"javascript:animatedcollapse.toggle('my-sidebar-$i')\"><img src=\"http://blablabla/intranetfront/wp-content/themes/whiteboard/images/downarrow.jpg\"></a></div>",
    	'after_title' => "</div><div id=\"my-sidebar-$i\" class=\"widgetcontent\"><div class=\"textwidget\">"
    ));
    $i++; // i is now 3
    register_sidebar( array(
    	'name' => "My sidebar $i",
    	'before_widget' => "<div class=\"xoxo2\">",
    	'after_widget' => "</div></div></div>",
    	'before_title' => "<div class=\"widgettitle\"><div style=\"float:right;display:inline\"><a href=\"javascript:animatedcollapse.toggle('my-sidebar-$i')\"><img src=\"http://blablabla/intranetfront/wp-content/themes/whiteboard/images/downarrow.jpg\"></a></div>",
    	'after_title' => "</div><div id=\"my-sidebar-$i\" class=\"widgetcontent\"><div class=\"textwidget\">"
    ));
    ?>

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Widget Unique Id’ is closed to new replies.