WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Problem with Dynamic Sidebars (7 posts)

  1. MCWebdesign
    Member
    Posted 4 years ago #

    Hi, hoping someone can help.

    I have created a site with 6 sidebars names:
    sidebar.php
    sidebar-events.php
    sidebar-main.php
    sidebar-mission.php
    sidebar-resources.php
    sidebar-services.php

    I have registered them in the functions.php flie which reads as follows:

    <?php
    /**
     * @package WordPress
     * @subpackage Classic_Theme
     */
    
    automatic_feed_links();
    
    if ( function_exists('register_sidebar') )
    	register_sidebar(array(
    	'before_widget' => '<li id="%1$s" class="widget %2$s">',
    'after_widget' => '</li>',
    'before_title' => '',
    'after_title' => '',
    	));
    
    ?>
    <?php if ( function_exists ('register_sidebar')) {
        register_sidebar ('main');
    } ?>
    <?php if ( function_exists ('register_sidebar')) {
        register_sidebar ('events');
    } ?>
    <?php if ( function_exists ('register_sidebar')) {
        register_sidebar ('mission');
    } ?>
    <?php if ( function_exists ('register_sidebar')) {
        register_sidebar ('services');
    } ?>
    <?php if ( function_exists ('register_sidebar')) {
        register_sidebar ('resources');
    } ?>

    And all the sidebars show up in the widgets section of the admin area.

    Each page calls the appropriate sidebar using `
    <?php get_sidebar(6); ?>`

    I have tried using <?php include ('sidebar-resources.php') ?> and <?php get_sidebar(resources); ?> But the only sidebar that i can get to show is the default sidebar (with dynamic content)

    Any ideas?

    Oh the site is http://www.stjamescarlisle.org.uk

  2. sleeplessinDC
    Member
    Posted 4 years ago #

    In your pages, you just need
    <?php get_sidebar(); ?>

    Then in your sidebar.php file, call each sidebar like this:
    <ul class="sidebar_list">
    <?php if (!function_exists('dynamic_sidebar') || !dynamic_sidebar(main)) : ?>

    <?php endif; ?>

    <?php if (!function_exists('dynamic_sidebar') || !dynamic_sidebar(events)) : ?>

    <li class="widget">
    <?php ec3_get_calendar(); ?>

    <li class="widget">Events
    <?php ec3_get_events(5); ?>

    <?php endif; ?>

    <?php if (!function_exists('dynamic_sidebar') || !dynamic_sidebar(mission)) : ?>

    <?php endif; ?>

    and so forth.

  3. sleeplessinDC
    Member
    Posted 4 years ago #

    For some reason the code above omitted the closing
    and so forth.
    </ul>

  4. MCWebdesign
    Member
    Posted 4 years ago #

    In your pages, you just need
    <?php get_sidebar(); ?>

    What do i put in the barckets of get sidebar to call each individual sidebar?

    this is the code i have in each of the sidebar.php files (which works fine for sidebar.php) it just doesnt work for the others

    <!-- begin sidebar -->
    
    <div id="sidebar">
    
    <ul>
    
    <?php /* Widgetized sidebar, if you have the plugin installed. */
     if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar() ) : ?>
    
    <?php wp_list_pages('title_li=' . __('Pages:')); ?>
    
    <?php wp_list_bookmarks('title_after=&title_before='); ?>
    
    <?php wp_list_categories('title_li=' . __('Categories:')); ?>
    
    <li id="search">
    
    <label for="s">
    <?php _e('Search:'); ?>
    </label>
    
    <form id="searchform" method="get" action="<?php bloginfo('home'); ?>">
    
    <div>
    
    <input type="text" name="s" id="s" size="15" /><br />
    
    <input type="submit" value="<?php esc_attr_e('Search'); ?>" />
    
    </div>
    
    </form>
    
    </li>
    
    <li id="archives"><?php _e('Archives:'); ?>
    
    <ul>
    
    <?php wp_get_archives('type=monthly'); ?>
    
    </ul>
    
    </li>
    
    <li id="meta">
    <?php _e('Meta:'); ?>
    
    <ul>
    
    <?php wp_register(); ?>
    
    <li>
    <?php wp_loginout(); ?>
    </li>
    
    <li>
    <a href="<?php bloginfo('rss2_url'); ?>" title="<?php _e('Syndicate this site using RSS'); ?>">
    
    <?php _e('<abbr title="Really Simple Syndication">RSS</abbr>'); ?></a>
    </li>
    
    <li>
    
    <a href="<?php bloginfo('comments_rss2_url'); ?>" title="<?php _e('The latest comments to all posts in RSS'); ?>">
    <?php _e('Comments <abbr title="Really Simple Syndication">RSS</abbr>'); ?></a>
    </li>
    
    <li>
    <a href="http://validator.w3.org/check/referer" title="<?php _e('This page validates as XHTML 1.0 Transitional'); ?>">
    <?php _e('Valid <abbr title="eXtensible HyperText Markup Language">XHTML</abbr>'); ?></a>
    </li>
    
    <li>
    <a href="http://gmpg.org/xfn/"><abbr title="XHTML Friends Network">XFN</abbr></a>
    </li>
    
    <li>
    <a href="http://wordpress.org/" title="<?php _e('Powered by WordPress, state-of-the-art semantic personal publishing platform.'); ?>">
    <abbr title="WordPress">WP</abbr></a></li>
    
    <?php wp_meta(); ?>
    </ul>
    
    </li>
    
    <?php endif; ?>
    
    </ul>
    
    </div>
    
    <!-- end sidebar -->
  5. MCWebdesign
    Member
    Posted 4 years ago #

    Ahh I just figured out what you are meaning. so my sidebar code now looks like this, though i still can't quite figure out how you tell which sidebar to appear on which page from this?

    <!-- begin sidebar -->
    
    <div id="sidebar">
    
    <ul>
    
    <?php /* Widgetized sidebar, if you have the plugin installed. */
     if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar() ) : ?>
    
    <?php wp_list_pages('title_li=' . __('Pages:')); ?>
    
    <?php wp_list_bookmarks('title_after=&title_before='); ?>
    
    <?php wp_list_categories('title_li=' . __('Categories:')); ?>
    
    <li id="search">
    
    <label for="s">
    <?php _e('Search:'); ?>
    </label>
    
    <form id="searchform" method="get" action="<?php bloginfo('home'); ?>">
    
    <div>
    
    <input type="text" name="s" id="s" size="15" /><br />
    
    <input type="submit" value="<?php esc_attr_e('Search'); ?>" />
    
    </div>
    
    </form>
    
    </li>
    
    <li id="archives"><?php _e('Archives:'); ?>
    
    <ul>
    
    <?php wp_get_archives('type=monthly'); ?>
    
    </ul>
    
    </li>
    
    <li id="meta">
    <?php _e('Meta:'); ?>
    
    <ul>
    
    <?php wp_register(); ?>
    
    <li>
    <?php wp_loginout(); ?>
    </li>
    
    <li>
    <a href="<?php bloginfo('rss2_url'); ?>" title="<?php _e('Syndicate this site using RSS'); ?>">
    
    <?php _e('<abbr title="Really Simple Syndication">RSS</abbr>'); ?></a>
    </li>
    
    <li>
    
    <a href="<?php bloginfo('comments_rss2_url'); ?>" title="<?php _e('The latest comments to all posts in RSS'); ?>">
    <?php _e('Comments <abbr title="Really Simple Syndication">RSS</abbr>'); ?></a>
    </li>
    
    <li>
    <a href="http://validator.w3.org/check/referer" title="<?php _e('This page validates as XHTML 1.0 Transitional'); ?>">
    <?php _e('Valid <abbr title="eXtensible HyperText Markup Language">XHTML</abbr>'); ?></a>
    </li>
    
    <li>
    <a href="http://gmpg.org/xfn/"><abbr title="XHTML Friends Network">XFN</abbr></a>
    </li>
    
    <li>
    <a href="http://wordpress.org/" title="<?php _e('Powered by WordPress, state-of-the-art semantic personal publishing platform.'); ?>">
    <abbr title="WordPress">WP</abbr></a></li>
    
    <?php wp_meta(); ?>
    </ul>
    
    </li>
    
    <?php endif; ?>
    
    <?php /* Widgetized sidebar, if you have the plugin installed. */
     if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('main') ) : ?>
    <?php endif; ?>
    
    <?php /* Widgetized sidebar, if you have the plugin installed. */
     if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('events') ) : ?>
    <?php endif; ?>
    
    <?php /* Widgetized sidebar, if you have the plugin installed. */
     if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('mission') ) : ?>
    <?php endif; ?>
    
    <?php /* Widgetized sidebar, if you have the plugin installed. */
     if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('resources') ) : ?>
    <?php endif; ?>
    
    <?php /* Widgetized sidebar, if you have the plugin installed. */
     if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('services') ) : ?>
    <?php endif; ?>
    
    </ul>
    
    </div>
    
    <!-- end sidebar -->
  6. MCWebdesign
    Member
    Posted 4 years ago #

    Ok so i've had a bit more of a look around and i think i have made my references more exact.
    I am calling the sidebar as such
    <?php get_sidebar('sidebar-main'); ?>
    the functions.php file is as so:

    <?php
    /**
     * @package WordPress
     * @subpackage Classic_Theme
     */
     if ( function_exists('register_sidebar') )
    register_sidebar(array('name'=>'')); ?>
    <?php if ( function_exists('register_sidebar') )
    register_sidebar(array('name'=>'sidebar-main')); ?>
    <?php if ( function_exists('register_sidebar') )
    register_sidebar(array('name'=>'sidebar-events')); ?>
    <?php if ( function_exists('register_sidebar') )
    register_sidebar(array('name'=>'sidebar-mission')); ?>
    <?php if ( function_exists('register_sidebar') )
    register_sidebar(array('name'=>'sidebar-services')); ?>
    <?php if ( function_exists('register_sidebar') )
    register_sidebar(array('name'=>'sidebar-resources')); ?>

    And I can edit the sidebars in admin ok, but only the first sidebar shows on the pages.

    Please can someone help?

  7. MCWebdesign
    Member
    Posted 4 years ago #

    I Managed to resolve this using php include in the end (even though it hadnt worked earlier)

Topic Closed

This topic has been closed to new replies.

About this Topic