2016-03-01 73 views
-2

请有人告诉我如何做到这一点?我的主题(寓言)没有内置的边栏,我需要一个用于我的主页。如何为没有侧边栏的主题创建窗口化边栏?

非常感谢!

+1

你试过了什么?你在哪里看?为什么它不起作用? – Auzias

+0

如果你的主题没有提供侧边栏,你可以1)停止使用它,并移动到完全不同的边栏和2)停止使用它,并创建一个边栏的儿童主题。我没有看到第三个选项。 –

回答

0
  1. 创建一个儿童主题。
  2. 创建一个文件sidebar.php。

  3. 在你的sidebar.php文件必须至少使用以下功能:在你的孩子的主题,您必须使用以下功能您functions.php文件dynamic_sidebar()

  4. 此外:register_sidebar()

  5. 将边栏添加到您的子主题中(最有可能在被覆盖的index.php文件中)

  6. 设计侧边栏以将其与主题正确集成。

如需进一步资料看WordPress的法典:

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

0

在functions.php文件将这个:

<?php 
// Declare sidebar widget zone 
register_sidebars(1, 
array(
    'name' => 'My Widget Area', 
    'before_widget' => '<div id="%1$s" class="widget %2$s">', 
    'after_widget' => '</div>', 
    'before_title' => '<h3 class="widgettitle">', 
    'after_title' => '</h3>' 
    ) 
    ); 
?> 

然后把这个地方在你想要显示小部件区域的主题中:

<?php if (function_exists('dynamic_sidebar') && dynamic_sidebar('My Widget Area')) : else : ?><?php endif; ?>