I'm trying to figure out how to auto-generate widgets for a static Page. I'm pretty close - well actually, I've doe it pretty simply... but my issue is I'd like to have the sidebars in the "Widgets" are have names instead of numbers, so I can easily tell which one goes with what Page.
This is what I have so far in my functions.php file:
$pages = get_pages();
$num = count($pages);
if ( function_exists('register_sidebar') ) {
register_sidebars($num, array(
'name'=> 'Sidebar %d',
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3>',
'after_title' => '</h3>',
));
}
And with that, I have a sidebar registered in my Widgets area for each Page I have created (right now, I have 10 static Pages - and I have 10 sidebars showing up in the Widgets area) - but they are numbers - saying "Sidebar 1", "Sidebar 2," etc.
What I'd *like* to do is pull in the Page *name* instead. I actually had that working too, sort of. Before the above, I had this:
$pages = get_pages();
if ( function_exists('register_sidebar') ) {
foreach($pages as $p) {
$name = $p->post_title;
register_sidebar(array(
'name'=> $name . ' Sidebar',
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3>',
'after_title' => '</h3>',
));
}
}
And the widgets *did* indeed register sidebars as "Pagename Sidebar" ("Pagename" being the title of all the Pages I have created), but on the front end of the site, I get an error message:
Catchable fatal error: Object of class stdClass could not be converted to string in /wp-includes/classes.php on line 273
So would anyone have any suggestions on how I can correct this to give me the *names* of the Pages, rather than numbers? Thanks :)