【问题标题】:cant change wordpress sidebar items无法更改 wordpress 侧边栏项目
【发布时间】:2012-10-17 22:15:22
【问题描述】:

我有一个带有侧边栏的 wordpress 网站,该网站以我下载的主题为主题。

在外观 > 菜单中,我创建了一个新菜单,然后将侧栏菜单下拉列表设置为新创建的菜单,但是当您访问网站时,它没有任何区别.. 旧菜单仍然存在.. .

所以我从主题中查看了代码编辑器,但我不知道如何更改它,所以它可以从我新创建的菜单中工作,我希望有人可以帮助我.. 这是 sidebar.php代码和sidebar-init.php

sidebar-init.php

<?php
function elegance_widgets_init() {
    // Header Widget
    // Location: right after the navigation
    register_sidebar(array(
        'name'                  => 'Header',
        'id'                        => 'header-sidebar',
        'description'   => __( 'Located at the top of pages.'),
        'before_widget' => '<div id="%1$s" class="widget">',
        'after_widget' => '</div>',
        'before_title' => '<h3>',
        'after_title' => '</h3>',
    ));
    // Sidebar Widget
    // Location: the sidebar
    register_sidebar(array(
        'name'                  => 'Sidebar',
        'id'                        => 'main-sidebar',
        'description'   => __( 'Located at the right side of pages.'),
        'before_widget' => '<div id="%1$s" class="widget">',
        'after_widget' => '</div>',
        'before_title' => '<h3>',
        'after_title' => '</h3>',
    ));
    // Contact Form Widget
    // Location: Contacts page
    register_sidebar(array(
        'name'                  => 'Contact Form',
        'id'                        => 'contact_form',
        'description'   => __( 'Located at the left side of Contacts page.'),
        'before_widget' => '<div id="%1$s">',
        'after_widget' => '</div>',
        'before_title' => '<h3>',
        'after_title' => '</h3>',
    ));
    // Address Widget
    // Location: Contacts page
    register_sidebar(array(
        'name'                  => 'Address',
        'id'                        => 'address',
        'description'   => __( 'Located at the right side of Contacts page.'),
        'before_widget' => '<div id="%1$s" class="widget">',
        'after_widget' => '</div>',
        'before_title' => '<h3>',
        'after_title' => '</h3>',
    ));
    // Footer Widget Area
    // Location: at the top of the footer, above the copyright
    register_sidebar(array(
        'name'                  => 'First footer widget area',
        'id'                        => 'first-footer-widget-area',
        'description'   => __( 'Located at the bottom of pages.'),
        'before_widget' => '<div id="%1$s" class="widget-area">',
        'after_widget' => '</div>',
        'before_title' => '<h4>',
        'after_title' => '</h4>',
    ));
    // Footer Widget Area
    // Location: at the top of the footer, above the copyright
    register_sidebar(array(
        'name'                  => 'Second footer widget area',
        'id'                        => 'second-footer-widget-area',
        'description'   => __( 'Located at the bottom of pages.'),
        'before_widget' => '<div id="%1$s" class="widget-area">',
        'after_widget' => '</div>',
        'before_title' => '<h4>',
        'after_title' => '</h4>',
    ));
    // Footer Widget Area
    // Location: at the top of the footer, above the copyright
    register_sidebar(array(
        'name'                  => 'Third footer widget area',
        'id'                        => 'third-footer-widget-area',
        'description'   => __( 'Located at the bottom of pages.'),
        'before_widget' => '<div id="%1$s" class="widget-area">',
        'after_widget' => '</div>',
        'before_title' => '<h4>',
        'after_title' => '</h4>',
    ));
    // Footer Widget Area
    // Location: at the top of the footer, above the copyright
    register_sidebar(array(
        'name'                  => 'Fourth footer widget area',
        'id'                        => 'fourth-footer-widget-area',
        'description'   => __( 'Located at the bottom of pages.'),
        'before_widget' => '<div id="%1$s" class="widget-area">',
        'after_widget' => '</div>',
        'before_title' => '<h4>',
        'after_title' => '</h4>',
    ));

}
/** Register sidebars by running elegance_widgets_init() on the widgets_init hook. */
add_action( 'widgets_init', 'elegance_widgets_init' );
?>

sidebar.php

<aside id="sidebar" class="grid_6 omega">
    <?php if ( ! dynamic_sidebar( 'Sidebar' )) : ?>

        <div id="sidebar-nav" class="widget menu">
            <h3>Navigation</h3>
            <?php wp_nav_menu( array('menu' => 'Sidebar Menu' )); ?> <!-- editable within the Wordpress backend -->
        </div>


    <?php endif; ?>
</aside><!--sidebar-->

任何帮助将不胜感激

【问题讨论】:

    标签: wordpress sidebar woocommerce


    【解决方案1】:
    <div id="sidebar-nav" class="widget menu">
                <h3>Navigation</h3>
                <?php wp_nav_menu( array('menu' => 'Catalogue' )); ?> <!-- editable within the Wordpress backend -->
    </div>
    

    只需更改 wp_nav_menu(array('menu' => 'Catalogue')) 中的值这将调用您的菜单名为“目录”,主题声明您可以从后端更改所选菜单

    【讨论】:

    • 另外,请确保在外观->小部件->侧边栏下确保这是空的,并且该区域中没有小部件,否则您的菜单不会显示!..
    • 好的,这有助于更改条目!我对此感到很兴奋,因为它花了我很长时间才能找到任何地方。但它改变了菜单的风格。我将在我的问题之前和之后添加图片,以便您有更好的主意。
    • 实际上我现在似乎无法找回它...... :( 继续努力会让你知道我是怎么走的......但是你知道为什么我在使用这段代码时会失去我的风格。
    • 老实说,我看不出它为什么会失去它的风格,也许你可以把它恢复到原来的样子,检查元素,看看有什么变化,什么没有吨?可能是另一个菜单分配了一些类
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-07-22
    • 2013-08-27
    相关资源
    最近更新 更多