Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Example theme code for Bootstrap Feature Widgets plugin
<?php
// Outputting the widget area on your homepage
// Accomodates one to four active widget areas, fits bootstrap columns accordingly
// front-page.php
$widget_count = 0;
for ($i = 1; $i <= 4; $i++){
if ( is_active_sidebar('homepage-widget-area-'.$i) ) $widget_count++;
}
if ( $widget_count > 0) {
$widget_column_class = floor(12 / $widget_count);
echo '<div class="row homepage-widgets">';
for ($i = 1; $i <= 4; $i++){
echo '<div class="col-md-'.$widget_column_class.'">';
if ( is_active_sidebar('homepage-widget-area-'.$i) ) {
dynamic_sidebar( 'homepage-widget-area-'.$i );
}
echo '</div>';
}
echo '</div>';
}
?>
<?php
// Activating Four Widget areas in your theme
// functions.php
function mysite_widgets_init() {
for($i = 1; $i <= 4; $i++){
register_sidebar( array(
'name' => "Homepage - $i",
'id' => "homepage-widget-area-$i",
'description' => "Widget area number $i on the homepage.",
'before_widget' => '',
'after_widget' => '',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
) );
}
}
add_action( 'widgets_init', 'mysite_widgets_init' );
?>
/* Some style tweaks to make everything look as you'd like */
/* style.css */
.homepage-widgets .glyphicon {
font-size:100px;
color:#D6A200;
}
.homepage-widgets .bootstrap-feature-widget-news {
padding:0;
list-style-type: none;
}
.homepage-widgets .bootstrap-feature-widget-news li:before{
content: "\00BB";
margin-right:10px;
}
.homepage-widgets .bootstrap-feature-widget-news a {
color:#333;
}
.homepage-widgets .bootstrap-feature-widget-news a:hover {
color:#2a6496;
text-decoration:none;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment