Widget Unique Id
-
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>' ) );
-
See the examples given here.
http://codex.wordpress.org/Function_Reference/register_sidebar
http://codex.wordpress.org/Function_Reference/register_sidebarsEach example uses a unique ID for each sidebar.
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
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\">" )); ?>
The topic ‘Widget Unique Id’ is closed to new replies.