WordPress 主题创建:显示的页面上没有小部件区域 [英] WordPress theme creation : There are no widget areas on the page shown

查看:38
本文介绍了WordPress 主题创建:显示的页面上没有小部件区域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 WordPress 的新手,我正在从头开始创建一个主题.
我想创建一个小部件区域,但自定义面板总是告诉:

I am new to WordPress and i am creating a theme from scratch.
I want to create a widget area, but the customize panel always tells :

显示的页面上没有小部件区域,但是此主题中的其他页面确实有它们

你们如何创建小部件区域?你能告诉我需要在我的文件中放入什么吗?

How do you guys create a widget area ? Could you please tell me what do I need to put in my files ?

谢谢

推荐答案

用于在 Wordpress 中注册小部件:

For Registering Widget In Wordpress:

将此代码添加到您的主题functions.php文件中.

Add this code Into your theme functions.php file.

add_action( 'widgets_init', 'theme_slug_widgets_init' );
function theme_slug_widgets_init() {
    register_sidebar( array(
        'name' => __( 'Main Sidebar', 'theme-slug' ),
        'id' => 'sidebar-1',
        'description' => __( 'Widgets in this area will be shown on all posts and pages.', 'theme-slug' ),
        'before_widget' => '',
    'after_widget'  => '',
    'before_title'  => '',
    'after_title'   => '',
    ) );
}

您应该使用自己的主题 slug,而不是 theme_slug_.您也可以查看此页面以获取更多信息.

Instead of theme_slug_ you should use your own theme slug. Also you can check this page for more information.

在任何自定义模板中注册小部件后或您想要显示该小部件的位置:

After Registering Widget Write in Any Custom Template Or where you want to display that Widget:

<?php get_sidebar('Main Sidebar'); ?>

https://codex.wordpress.org/Function_Reference/register_sidebar

这篇关于WordPress 主题创建:显示的页面上没有小部件区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆