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

"

"

X vBulletin 4.2.2 Debug Information

  • Page Generation 0.11042 seconds
  • Memory Usage 2,961KB
  • Queries Executed 13 (?)
More Information
Template Usage (30):
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (4)bbcode_code
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (3)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (3)postbit
  • (3)postbit_onlinestatus
  • (3)postbit_wrapper
  • (1)showthread_list
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (27):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./includes/functions_threadedmode.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (72):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids_threaded
  • showthread_threaded_construct_link
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • tag_fetchbit
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates