如何在WordPress中创建侧边栏

发布于 2025-01-30 05:37:09 字数 60 浏览 1 评论 0原文

我购买了不显示任何侧边栏的争议主题。 我想保留主题,但在主页上显示侧边栏。

有办法这样做吗?

I have purchased the Disputo theme that doesn't display any sidebars.
I want to keep my theme but display the sidebar on the home page.

Is there a way to do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

猫九 2025-02-06 05:37:09

您可以从外观编辑侧边栏>小部件。为了显示侧边栏,您必须从页面编辑中选择侧栏模板。根据不同的主题会发生变化,但这适用于大多数主题。

you can edit sidebar from appearance > widget. in order display sidebar you have to choose sidebar template from page edit. there will be changes according to different themes , but this works for most of the themes out there.

jJeQQOZ5 2025-02-06 05:37:09

如果您没有侧栏选项,则可以将此代码放在function.php文件

/**
 * function.php
 */
function wpdocs_theme_slug_widgets_init() {
    register_sidebar( array(
        'name'          => __( 'Main Sidebar', 'textdomain' ),
        'id'            => 'sidebar-1',
        'description'   => __( 'Widgets in this area will be shown on all posts and pages.', 'textdomain' ),
        'before_widget' => '<li id="%1$s" class="widget %2$s">',
        'after_widget'  => '</li>',
        'before_title'  => '<h2 class="widgettitle">',
        'after_title'   => '</h2>',
    ) );
}
add_action( 'widgets_init', 'wpdocs_theme_slug_widgets_init' );

上,然后将此代码index.php放置以显示输出

<?php if ( is_active_sidebar( 'sidebar-1' ) ) { ?>
    <ul id="sidebar">
        <?php dynamic_sidebar('sidebar-1'); ?>
    </ul>
<?php } ?>

If you have no sidebar option then you can put this code on function.php file

/**
 * function.php
 */
function wpdocs_theme_slug_widgets_init() {
    register_sidebar( array(
        'name'          => __( 'Main Sidebar', 'textdomain' ),
        'id'            => 'sidebar-1',
        'description'   => __( 'Widgets in this area will be shown on all posts and pages.', 'textdomain' ),
        'before_widget' => '<li id="%1$s" class="widget %2$s">',
        'after_widget'  => '</li>',
        'before_title'  => '<h2 class="widgettitle">',
        'after_title'   => '</h2>',
    ) );
}
add_action( 'widgets_init', 'wpdocs_theme_slug_widgets_init' );

Then put this code index.php for showing output

<?php if ( is_active_sidebar( 'sidebar-1' ) ) { ?>
    <ul id="sidebar">
        <?php dynamic_sidebar('sidebar-1'); ?>
    </ul>
<?php } ?>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文