Tag Archives: sidebar

Register Sidebars


/*
* Legal Main Sidebar
*/

function legal_widgets_init() {

register_sidebar(array(
'name' => __('Main Sidebar', 'legal'),
'id' => 'sidebar-1',
'description' => __('Main sidebar that appears on the right.', 'legal'),
'before_widget' => '<aside id="%1$s" class="sidebar-widget widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
));

register_sidebar(array(
'name' => __('Footer Area One', 'legal'),
'id' => 'footer-1',
'description' => __('Footer Area One that appears on footer.', 'legal'),
'before_widget' => '<aside id="%1$s" class="footer-widget widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h3>',
'after_title' => '</h3>',
));

register_sidebar(array(
'name' => __('Footer Area Two', 'legal'),
'id' => 'footer-2',
'description' => __('Footer Area Two that appears on footer.', 'legal'),
'before_widget' => '<aside id="%1$s" class="footer-widget widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h3>',
'after_title' => '</h3>',
));

register_sidebar(array(
'name' => __('Footer Area Three', 'legal'),
'id' => 'footer-3',
'description' => __('Footer Area Three that appears on footer.', 'legal'),
'before_widget' => '<aside id="%1$s" class="footer-widget widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h3>',
'after_title' => '</h3>',
));

register_sidebar(array(
'name' => __('Footer Area Four', 'legal'),
'id' => 'footer-4',
'description' => __('Footer Area Four that appears on footer.', 'legal'),
'before_widget' => '<aside id="%1$s" class="footer-widget widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h3>',
'after_title' => '</h3>',
));
}

add_action('widgets_init', 'legal_widgets_init');



Display:


<div class="col-md-3 col-sm-6">
<?php if (is_active_sidebar('footer-1')) { ?>
<div class="footer-widget">
<?php dynamic_sidebar('footer-1'); ?>
</div>
<?php } ?>
</div>

Advertisements

Different widget in sidebar for different post and page

Add required widget in sidebar

Create Sidebar


register_sidebar(array(
'name' => __('Contact Attorny', 'legal'),
'id' => 'contact-attorny',
'description' => __('Contact Attorny sidebar that appears on the right.', 'legal'),
'before_widget' => '<aside id="%1$s" class="sidebar-widget widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<div class="sidebar-widget"><h3>',
'after_title' => '</h3></div>',
));

register_sidebar(array(
'name' => __('Twitter', 'legal'),
'id' => 'twitterfids',
'description' => __('Twitter that appears on the right.', 'legal'),
'before_widget' => '<aside id="%1$s" class="sidebar-widget widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<div class="sidebar-widget"><h3>',
'after_title' => '</h3></div>',
));

register_sidebar(array(
'name' => __('Blog Category', 'legal'),
'id' => 'bcats',
'description' => __('Blog Category that appears on the right.', 'legal'),
'before_widget' => '<aside id="%1$s" class="sidebar-widget widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<div class="sidebar-widget"><h3>',
'after_title' => '</h3></div>',
));
register_sidebar(array(
'name' => __('Practice Area', 'legal'),
'id' => 'practicearea',
'description' => __('Practice Area that appears on the right.', 'legal'),
'before_widget' => '<aside id="%1$s" class="sidebar-widget widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<div class="sidebar-widget"><h3>',
'after_title' => '</h3></div>',
));

Sidebar.php


<?php
$legal_options = get_option('legal_theme_options');
?>
<?php if ( is_singular('practice-areas') ) { ?>
<div class="sidebar-box">
<?php if (is_active_sidebar('contact-attorny')) {
dynamic_sidebar('contact-attorny'); }?>
</div>
<div class="sidebar-box">
<?php if (is_active_sidebar('twitterfids')) {
dynamic_sidebar('twitterfids'); }?>
</div>
<div class="sidebar-box">
<?php if (is_active_sidebar('practicearea')) {
dynamic_sidebar('practicearea'); }?>
</div>
<?php } ?>

<?php if ( is_singular('post') ) { ?>
<div class="sidebar-box">
<?php if (is_active_sidebar('contact-attorny')) {
dynamic_sidebar('contact-attorny'); }?>
</div>
<div class="sidebar-box">
<?php if (is_active_sidebar('twitterfids')) {
dynamic_sidebar('twitterfids'); }?>
</div>
<div class="sidebar-box">
<?php if (is_active_sidebar('bcats')) {
dynamic_sidebar('bcats'); }?>
</div>
<?php } ?>

<?php if(is_home()) { ?>
<div class="sidebar-box">
<?php if (is_active_sidebar('contact-attorny')) {
dynamic_sidebar('contact-attorny'); }?>
</div>
<div class="sidebar-box">
<?php if (is_active_sidebar('twitterfids')) {
dynamic_sidebar('twitterfids'); }?>
</div>
<div class="sidebar-box">
<?php if (is_active_sidebar('bcats')) {
dynamic_sidebar('bcats'); }?>
</div>
<?php } ?>

<?php if (is_page_template('page-template/testimonials.php')) { ?>
<div class="sidebar-box">
<?php if (is_active_sidebar('contact-attorny')) {
dynamic_sidebar('contact-attorny'); }?>
</div>
<div class="sidebar-box">
<?php if (is_active_sidebar('twitterfids')) {
dynamic_sidebar('twitterfids'); }?>
</div>
<div class="sidebar-box">
<?php if (is_active_sidebar('practicearea')) {
dynamic_sidebar('practicearea'); }?>
</div>
<?php } ?>

<?php if (is_page_template('page-template/case-results.php')) { ?>
<div class="sidebar-box">
<?php if (is_active_sidebar('practicearea')) {
dynamic_sidebar('practicearea'); }?>
</div>
<div class="sidebar-box">
<?php if (is_active_sidebar('twitterfids')) {
dynamic_sidebar('twitterfids'); }?>
</div>
<?php } ?>

<?php if (is_page(204)) { ?>
<div class="sidebar-box">
<?php if (is_active_sidebar('contact-attorny')) {
dynamic_sidebar('contact-attorny'); }?>
</div>
<div class="sidebar-box">
<?php if (is_active_sidebar('twitterfids')) {
dynamic_sidebar('twitterfids'); }?>
</div>
<?php } ?>

<?php if (is_page(269)) { ?>
<div class="sidebar-box">
<?php if (is_active_sidebar('contact-attorny')) {
dynamic_sidebar('contact-attorny'); }?>
</div>
<div class="sidebar-box">
<?php if (is_active_sidebar('twitterfids')) {
dynamic_sidebar('twitterfids'); }?>
</div>
<div class="sidebar-box">
<?php if (is_active_sidebar('bcats')) {
dynamic_sidebar('bcats'); }?>
</div>
<?php } ?>

<?php if (is_page(206)) { ?>
<div class="sidebar-box">
<?php if (is_active_sidebar('contact-attorny')) {
dynamic_sidebar('contact-attorny'); }?>
</div>
<div class="sidebar-box">
<?php if (is_active_sidebar('twitterfids')) {
dynamic_sidebar('twitterfids'); }?>
</div>
<div class="sidebar-box">
<div class="address_info">
<h4> <?php echo esc_attr($legal_options['contacttitles']); ?> </h4>
<div class="textwidget">
<ul>
<li>
<?php echo esc_attr($legal_options['contactaddresses']); ?><br>
Phone: <?php  echo esc_url($legal_options['pnumbers']); ?><br>
Fax: <?php  echo esc_attr($legal_options['faxnumbs']); ?><br>
E-mail: <a href="mailto:<?php echo sanitize_email($legal_options['cemails']); ?>"><?php echo sanitize_email($legal_options['cemails']); ?></a><br>
Website: <a href="<?php echo esc_url($legal_options['cweb']); ?>"><?php echo esc_url($legal_options['cweb']); ?></a> </li>
</ul>
</div>
</div>
</div>

<?php } ?>

PHP code applay in text widget

Paste in functions.php

function php_text($text) {
 if (strpos($text, '<' . '?') !== false) {
 ob_start();
 eval('?' . '>' . $text);
 $text = ob_get_contents();
 ob_end_clean();
 }
 return $text;
}
add_filter('widget_text', 'php_text', 99);

Child pages of parent page menu in sidebar

You can also use this plugin:
http://wordpress.org/plugins/child-page-navigation/
if u want add main title as main page then use this plugin:
https://wordpress.org/plugins/children-pages/screenshots/
by default all childpages short by name, if u want add desiding order then:
got to plugin’s => edit => and replace this line
$pages = wp_list_pages(‘depth=0&title_li=&child_of=’.$id.’&echo=0&sort_column=menu_order’);

past in sidebar.php 

<?php global $post;?>
<?php
if($post->post_parent){
$parent_title = get_the_title($post->post_parent);
$children = wp_list_pages(“depth=1&title_li=&child_of=”.$post->post_parent.”&echo=0″); // append the list of children pages to the same $children variable
}
if ($parent_title) { ?>
<h2 class=”widgettitle”><?php echo $parent_title; ?></h2>
<?php }

if ($children) { ?>
<ul class=”submenu”>
<li><?php echo $children; /*print list of pages*/ ?></li>
</ul>
<?php } ?>

%d bloggers like this: