/    Sign up×
Community /Pin to ProfileBookmark

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’); ?>[/CODE]
    [B]3. Now I need to create a duplicate ad widget (in my WP dashboard) and update my new header-main.php to call it?[/B]
    [B]
    Not sure how to do step #3?[/B]
  • 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; ?>

    [/CODE]

    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’ );
    [/CODE]

    I am teaching myself so any help from a pro is appreciated.

    to post a comment
    PHP

    2 Comments(s)

    Copy linkTweet thisAlerts:
    @ne_plusauthorJun 10.2013 — 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>',
    ));
    ?>
    [/CODE]
    Copy linkTweet thisAlerts:
    @ne_plusauthorJun 10.2013 — 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:UsersMeDocumentsWebsites[url]www.domain.devwp-contentthemesthemenamecustom-functions.php:15[/url]) in C:UsersMeDocumentsWebsites[url]www.domain.devwp-login.php[/url] on line 368

    Warning: Cannot modify header information - headers already sent by (output started at C:UsersMeDocumentsWebsites[url]www.domain.devwp-contentthemesthemenamecustom-functions.php:15[/url]) in C:UsersMeDocumentsWebsites[url]www.domain.devwp-login.php[/url] on line 380

    Warning: Cannot modify header information - headers already sent by (output started at C:UsersMeDocumentsWebsites[url]www.domain.devwp-contentthemesthemenamecustom-functions.php:15[/url]) in C:UsersMeDocumentsWebsites[url]www.domain.devwp-includespluggable.php[/url] on line 697 -- this repeats on several lines?
    ×

    Success!

    Help @ne_plus spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 5.24,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,

    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,
    )...