www.webdeveloper.com
Results 1 to 3 of 3

Thread: How to Create Dynamic Sidebar in WordPress?

Hybrid View

  1. #1
    Join Date
    Jan 2010
    Posts
    43

    How to Create Dynamic Sidebar in WordPress?

    I am working with a theme that has a header ad widget (which displays an ad block at the top of each page). But, I want the homepage to show a different ad block than the rest of the site. I am teaching myself so any help from a PRO is appreciated.

    So far, I have:

    1. Created a new header file (header-main.php)
    2. Called the new header file from my index.php file
    Code:
    <?php get_header('main'); ?>
    3. Now I need to create a duplicate ad widget (in my WP dashboard) and update my new header-main.php to call it?

    Not sure how to do step #3?


    The ad widget code in my header-main.php file is:

    Code:
    <div class="body-wrapper">
    	
    	<header id="header">
    TESTING
    		<?php if ( wpb_option('header-widget-ads') ): ?>
    			<div class="ads-header group">
    				<div class="container">
    					<div class="grid one-full">
    						<ul><?php dynamic_sidebar('widget-ads-header'); ?></ul>
    					</div>
    				</div>
    			</div><!--/.ads-header-->
    		<?php endif; ?>
    I have reviewed my functions.php file but I am not sure what code to duplicate?

    Code:
    <?php
    
    /**
    
    	Many tutorials suggest placing code in the functions.php file. This file
     	is used to configure the theme's framework. Editing may break your theme.
    
    	Please use the custom-functions.php file for customization. Thanks! :)
    
    **/
    
    // Air Framework
    $air = require( get_template_directory() . '/air/base/lib/air.php' );
    
    /*---------------------------------------------------------------------------*/
    /* Air Framework Configuration
    /*---------------------------------------------------------------------------*/
    
    // Theme configuration
    Air::mset(
    	array(
    		// Theme options
    		'theme-options'		=> 'themename',
    
    		// Text domain
    		'text-domain'		=> 'theme',
    
    		// Theme features
    		'features' => array(
    			'automatic-feed-links'	=> TRUE,
    			'post-thumbnails'		=> TRUE,
    			'post-formats'			=> array('audio','aside','chat','gallery','image','link','quote','status','video')
    		),
    
    		// Navigation menus
    		'nav-menus' => array(
    			'header'	=> 'Header',
    			'subheader'	=> 'Subheader',
    			'footer' 	=> 'Footer'
    		),
    
    		// Sidebars
    		'sidebars' => array(
    			array(
    				'id'			=> 'sidebar-default',
    				'name'			=> 'Default Sidebar',
    				'before_widget'	=> '<li id="%1$s" class="widget %2$s">',
    				'after_widget'	=> '</li>',
    				'before_title'	=> '<h3 class="widget-title group"><span>',
    				'after_title'	=> '</span></h3>',
    			)
    		),
    
    		// Widgets
    		'widgets' => array(
    			'widget-tabs' 	=> 'WPB_Widget_Tabs',
    			'widget-video' 	=> 'WPB_Widget_Video'
    		),
    
    		// Image sizes
    		'image-sizes' => array(
    			array(
    				'name'		=> 'size-format',
    				'width'		=> 720,
    				'height'	=> 0,
    				'crop'		=> FALSE
    			),
    			array(
    				'name'		=> 'size-thumbnail-tabs',
    				'width'		=> 192,
    				'height'	=> 128,
    				'crop'		=> TRUE
    			),
    			array(
    				'name'		=> 'size-thumbnail-medium',
    				'width'		=> 520,
    				'height'	=> 245,
    				'crop'		=> TRUE
    			),
    			array(
    				'name'		=> 'size-thumbnail-large',
    				'width'		=> 720,
    				'height'	=> 340,
    				'crop'		=> TRUE
    			),
    		),
    
    		// Styles
    		'styles' => array(
    			array(
    				'handle'	=> 'themename-custom',
    				'src'		=> get_template_directory_uri().'/custom.css',
    				'deps'		=> FALSE,
    				'ver'		=> '1.0'
    			),
    			array(
    				'handle'	=> 'style-responsive',
    				'src'		=> get_template_directory_uri().'/style-responsive.css',
    				'deps'		=> FALSE,
    				'ver'		=> '1.0'
    			),
    			array(
    			 	'handle'	=> 'font-awesome',
    				'src'		=> get_template_directory_uri().'/fonts/font-awesome.min.css',
    				'deps'		=> FALSE,
    				'ver'		=> '3.0'
    			)
    		),
    
    		// Javascript
    		'scripts' => array(
    			array(
    			 	'handle'	=> 'flexslider',
    				'src'		=> get_template_directory_uri().'/js/jquery.flexslider.min.js',
    				'deps'		=> array('jquery'),
    				'ver'		=> '2.1',
    				'footer'	=> TRUE
    			),
    			array(
    				'handle'	=> 'jplayer',
    				'src'		=> get_template_directory_uri().'/js/jquery.jplayer.min.js',
    				'ver'		=> '2.1.0',
    				'footer'	=> TRUE
    			),
    			array(
    				'handle'	=> 'sharrre',
    				'src'		=> get_template_directory_uri().'/js/jquery.sharrre-1.3.4.min.js',
    				'deps'		=> array('jquery'),
    				'ver'		=> '1.3.4',
    				'footer'	=> TRUE
    			),
    			array(
    				'handle'	=> 'theme',
    				'src'		=> get_template_directory_uri().'/js/jquery.theme.js',
    				'deps'		=> array('jquery'),
    				'ver'		=> '1.0',
    				'footer'	=> TRUE
    			),
    		),
    
    		// Meta files
    		'meta-files' => array(
    			'meta-general.php'
    		),
    
    		// Help tabs
    		'help-tabs' => array(
    			'faq'	=> 'FAQ'
    		)
    	)
    );
    
    // Set content width based on theme's design
    if ( !isset( $content_width ) ) $content_width = 720;
    
    /*---------------------------------------------------------------------------*/
    
    // Add sections to theme options - slug, title
    Air::add_options_menu_item('general','General');
    Air::add_options_menu_item('blog','Blog');
    Air::add_options_menu_item('seo','SEO');
    Air::add_options_menu_item('header','Header');
    Air::add_options_menu_item('sidebar','Sidebar');
    Air::add_options_menu_item('footer','Footer');
    Air::add_options_menu_item('styling','Styling');
    Air::add_options_menu_item('javascript','JavaScript');
    
    // Add modules
    Air::add_module('login','Login');
    Air::add_module('maintenance','Maintenance');
    Air::add_module('sidebar','Sidebar');
    Air::add_module('social','Social');
    Air::add_module('breadcrumbs','Breadcrumbs');
    Air::add_module('related-posts','Related Posts');
    
    // Initialize framework
    $air->run();
    
    add_theme_support( 'woocommerce' );
    I am teaching myself so any help from a pro is appreciated.
    Last edited by ne_plus; 06-10-2013 at 01:08 PM.

  2. #2
    Join Date
    Jan 2010
    Posts
    43
    I just figured out how to ad the new widget, (see custom functions.php code below) but now I am unsure how to call it in the new header-main.php file?

    Does anyone know how to do this?

    Code:
     <?php
    
    /* --- Place custom functions below ---------------------------------------- */
    
    register_sidebar(array(
    	'id' => 'header-widget-ads-2',
    	'name' => 'Ads: Header 2',
    	'before_widget'	=> '<li id="%1$s" class="widget %2$s">',
    	'after_widget'	=> '</li>',
    	'before_title'	=> '<h3 class="widget-title group"><span>',
    	'after_title'	=> '</span></h3>',
     ));
     ?>

  3. #3
    Join Date
    Jan 2010
    Posts
    43
    The changes I made are resulting in the following errors in wp-includes? Does anyone know how to fix this?

    Warning: Cannot modify header information - headers already sent by (output started at C:\Users\Me\Documents\Websites\http://www.domain.dev\wp-content\the...nctions.php:15) in C:\Users\Me\Documents\Websites\www.domain.dev\wp-login.php on line 368

    Warning: Cannot modify header information - headers already sent by (output started at C:\Users\Me\Documents\Websites\http://www.domain.dev\wp-content\the...nctions.php:15) in C:\Users\Me\Documents\Websites\www.domain.dev\wp-login.php on line 380

    Warning: Cannot modify header information - headers already sent by (output started at C:\Users\Me\Documents\Websites\http://www.domain.dev\wp-content\the...nctions.php:15) in C:\Users\Me\Documents\Websites\www.domain.dev\wp-includes\pluggable.php on line 697 -- this repeats on several lines?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles