duankousong9637 2013-11-12 06:04
浏览 39

在WordPress中添加侧边栏

I'm trying to add two new sidebars on my WordPress website here, one on the left and the other on the right, the main content then will be in the middle. Making the layout a three column.

I am using a Ready! To be Theme with Ready! E-Commerce plugin, I have also made the child where I made most of the changes.

The problem is the sidebar is not appearing on the website itself. And when viewing the Widgets area under Appearance Menu the widget area I added does not appear even after registering it.

This is the code I inserted on the front-page.php:

<?php get_sidebar('left'); ?> 
<?php get_sidebar('right'); ?>

I then proceeded to create two sidebar.php files namely

sidebar-left.php which has the following code

<?php
/**
 * The Sidebar containing the main widget areas.
 *
 * @package Ready_ecommerce
 * @since Ready_ecommerce 0.1
 */
?>
<div id="secondary" class="widget-area sidebar" role="complementary">
        <?php do_action( 'before_sidebar' ); ?>
        <?php if ( ! dynamic_sidebar( 'sidebar-6' ) ) : ?>
                <aside id="search" class="widget widget_search">
                        <?php get_search_form(); ?>
                </aside>
                <aside id="archives" class="widget">
                        <h1 class="widget-title"><?php _e( 'Archives', 'ready_ecommerce' ); ?></h1>
                        <ul>
                                <?php wp_get_archives( array( 'type' => 'monthly' ) ); ?>
                        </ul>
                </aside>
                <aside id="meta" class="widget">
                        <h1 class="widget-title"><?php _e( 'Meta', 'ready_ecommerce' ); ?></h1>
                        <ul>
                                <?php wp_register(); ?>
                                <aside><?php wp_loginout(); ?></aside>
                                <?php wp_meta(); ?>
                        </ul>
                </aside>
        <?php endif; // end sidebar widget area ?>
</div><!-- #secondary .widget-area -->
<style type="text/css">
    #content {
        float: left;

    }
</style>

sidebar-right.php with the code:

<?php
/**
 * The Sidebar containing the main widget areas.
 *
 * @package Ready_ecommerce
 * @since Ready_ecommerce 0.1
 */
?>
<div id="secondary-2" class="widget-area sidebar" role="complementary">
        <?php do_action( 'before_sidebar' ); ?>
        <?php if ( ! dynamic_sidebar( 'sidebar-5' ) ) : ?>
                <aside id="search" class="widget widget_search">
                        <?php get_search_form(); ?>
                </aside>
                <aside id="archives" class="widget">
                        <h1 class="widget-title"><?php _e( 'Archives', 'ready_ecommerce' ); ?></h1>
                        <ul>
                                <?php wp_get_archives( array( 'type' => 'monthly' ) ); ?>
                        </ul>
                </aside>
                <aside id="meta" class="widget">
                        <h1 class="widget-title"><?php _e( 'Meta', 'ready_ecommerce' ); ?></h1>
                        <ul>
                                <?php wp_register(); ?>
                                <aside><?php wp_loginout(); ?></aside>
                                <?php wp_meta(); ?>
                        </ul>
                </aside>
        <?php endif; // end sidebar widget area ?>
</div><!-- #secondary .widget-area -->
<style type="text/css">
    #content {
        float: right;
        width: 759px;
    }
</style>

And last, added the following lines to functions.php

register_sidebar( array(
            'name' => __( 'Content Pages Right', 'ready_ecommerce' ),
            'id' => 'sidebar-5',
            'description' => __( 'Right sidebar area for content pages only. Not availabe at products or catalogue pages', 'ready_ecommerce' ),
            'before_widget' => '<aside id="%1$s" class="widget %2$s">',
            'after_widget' => "</aside>",
            'before_title' => '<h2 class="widget-title">',
            'after_title' => '</h2>',
        ) );
    register_sidebar( array(
            'name' => __( 'Content Pages Left', 'ready_ecommerce' ),
            'id' => 'sidebar-6',
            'description' => __( 'Left sidebar area for content pages only. Not availabe at products or catalogue pages', 'ready_ecommerce' ),
            'before_widget' => '<aside id="%1$s" class="widget %2$s">',
            'after_widget' => "</aside>",
            'before_title' => '<h2 class="widget-title">',
            'after_title' => '</h2>',
        ) );
  • 写回答

1条回答 默认 最新

  • douyan7916 2013-11-12 06:20
    关注

    Try this

    <?php if(function_exists('dynamic_sidebar') && dynamic_sidebar('sidebar-6')) : ?>
    
    <?php endif; ?>
    

    UPDATE:

    <div id="secondary" class="widget-area sidebar" role="complementary">
    <?php do_action( 'before_sidebar' ); ?>
    <?php if(function_exists('dynamic_sidebar') && dynamic_sidebar('sidebar-6')) : ?>
    <aside id="search" class="widget widget_search">
        <?php get_search_form(); ?>
    </aside>
    <aside id="archives" class="widget">
        <h1 class="widget-title"><?php _e( 'Archives', 'ready_ecommerce' ); ?></h1>
        <ul>
            <?php wp_get_archives( array( 'type' => 'monthly' ) ); ?>
        </ul>
    </aside>
    <aside id="meta" class="widget">
        <h1 class="widget-title"><?php _e( 'Meta', 'ready_ecommerce' ); ?></h1>
        <ul>
            <?php wp_register(); ?>
            <aside><?php wp_loginout(); ?></aside>
            <?php wp_meta(); ?>
        </ul>
    </aside>
    <?php endif; // end sidebar widget area ?>
    

    #content {float: left;}

    Please try the above code in sidebar-left.php and check from Appearance > Widgets . Drag the text widget into sidebar and write some demo text and check. Let me know your update.

    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题