Skip to content

Instantly share code, notes, and snippets.

@purzlbaum
Created February 6, 2014 15:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save purzlbaum/8846227 to your computer and use it in GitHub Desktop.
Save purzlbaum/8846227 to your computer and use it in GitHub Desktop.
Show for each page a sidebar in the WordPress widget section
// Dynamic Widgets
$myPages = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_type = 'page' OR post_type = 'teams' /* OR post_type = 'players' */ AND post_status = 'publish'");
foreach ($myPages as $q ){
$id = 'sidebar-'.$q->ID;
$namePref = "Parent - ";
if ($q->post_parent != 0){
$namePref = "Child - ";
}
$sbtitle = $q->post_title;
if ($sbtitle && function_exists('register_sidebar')){
register_sidebar(array(
'id' => $id,
'name' => $sbtitle ,
'before_widget' => '<div id="%1$s" class="sidebar-section %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3>',
'after_title' => '</h3>'
));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment