主题定制器:如何创建多层面板

时间:2015-08-23 作者:Pakpoom Tiwakornkit

有没有办法在主题定制器中创建深层子面板(如植物的根)?我一直在发展的主题似乎更加复杂。我认为,如果我们能够创建深层次的子面板,我们的定制页面将不会看起来凌乱,我们的用户将更容易定制主题,我们将能够使更复杂的WordPress主题更容易。下面的图片描述了我的想法。。。

Theme Customizer concept that I found on online tutorialsHere is sub panel that I wan to create

不幸的是,我已经尝试过搜索这个主题,但我只能找到在主题定制器中创建单层面板的方法another thread , 无法找到使子面板更深的方法。你能为我的生活遮光吗?

Update : 下面的代码是我用来创建面板和控件的一些代码,如image#1,它是单层面板。它们都很好用。

$wp_customize->add_panel(\'panel1\',
        array(
            \'title\' => \'Panel 1\',
            \'priority\' => 1,
            )
        );
        $wp_customize->add_section( \'section1\',
            array(
                \'title\' => \'This is section 1\',
                \'priority\' => 1,
                \'panel\' => \'panel1\'
                )
            );
            $wp_customize->add_setting(\'field1\', array(\'default\' => \'default text\'));
            $wp_customize->add_control(\'field1\', array(
                \'label\' => \'Text field\',
                \'section\' => \'section1\',
                \'type\' => \'text\',
                )
            );
我的问题是,我想创建一个新的面板,让它们粘在另一个面板上,这将使它看起来像根层次结构(图#2)。我认为,如果我们可以这样做,我们将能够制作更强大的主题定制器。然后我试图实现这个想法,并试图重写我的代码。不幸的是,它没有起作用。请检查下面的一个。

$wp_customize->add_panel(\'panel1\',
        array(
            \'title\' => \'Panel 1\',
            \'priority\' => 1,
            )
        );
        $wp_customize->add_section( \'section1\',
            array(
                \'title\' => \'This is section 1\',
                \'priority\' => 1,
                \'panel\' => \'panel1\'
                )
            );
            $wp_customize->add_setting(\'field1\', array(\'default\' => \'default text\'));
            $wp_customize->add_control(\'field1\', array(
                \'label\' => \'Text field\',
                \'section\' => \'section1\',
                \'type\' => \'text\',
                )
            );
        // I used the code below with a little hope that it will help me accomplish my idea, but it didn\'t work T^T.
        $wp_customize->add_panel(\'panel1_1\',
            array(
                \'title\' => \'Panel 1.1\',
                \'priority\' => 2,
                \'panel\' => \'panel1\' // I tried adding this line of code in order to let it depend on another panel
                )
            );
            $wp_customize->add_section( \'section1_1\',
            array(
                \'title\' => \'This is section 1\',
                \'priority\' => 1,
                \'panel\' => \'panel1_1\'
                )
            );
            $wp_customize->add_setting(\'field1_1\', array(\'default\' => \'default text\'));
            $wp_customize->add_control(\'field1_1\', array(
                \'label\' => \'Text field\',
                \'section\' => \'section1_1\',
                \'type\' => \'text\',
                )
            );
你能给我一个解决方案吗?我不知道如何使面板看起来像根层次结构。任何帮助都将不胜感激:)

2 个回复
最合适的回答,由SO网友:OriginalEXE 整理而成

对于任何来这里寻找这个的人来说,我在与它战斗了几个小时后就可以做到了。

代码有点广泛,所以不想在这里发布,(如果更好的话,mods现在可以让我发布),相反,我创建了一个要点:https://gist.github.com/OriginalEXE/9a6183e09f4cae2f30b006232bb154af

它的作用是它基本上允许您指定panel 面板上的属性(用于在面板下嵌套面板)和section 截面上的属性(用于在截面下嵌套截面)。

备注:

php代码包括如何创建面板/子面板/节/子节的示例。值得注意的是,您使用我创建的子类实例化了新面板/节,而不是直接调用$wp-customize->add_panel 并将其传递给一个配置数组panel 属性,该属性应与panel 在父节中,我尝试用尽可能少的代码来完成这项工作,并且不重写任何可能会破坏其他人代码的内容。如果他们在未来的版本中更改逻辑,可能需要进行一些重构,我尽可能做到这一点。

SO网友:cjbj

目前,不可能有超过面板、部分和控件。扩展该系统需要在WP进行大量编程。由于定制器的尺寸很窄,如果有这么多嵌套面板,也很容易丢失。所以这可能也不可取。

结束

相关推荐

Responsive Admin Themes

我在看这个管理主题的示例(http://themepixels.com/main/themes/demo/webpage/shamcey/dashboard.html). 至于标签为“Navigation”的左侧管理栏,有没有一种方法可以在不使用插件的情况下实现这种类型的左侧仪表板管理菜单?我想用css、js或Jquery来实现这一点,任何处理编码的东西都可以。