Register/Get sidebar?

时间:2012-09-15 作者:qwerty

我似乎不太明白它是怎么工作的。

默认情况下,我在侧栏中有一个侧栏。我使用加载的phpget_sidebar();. 这很好(无需注册),但我有一个自定义页面模板,用于另一个页面,我想加载另一个侧栏。我知道我可以使用include(\'filename\')来加载它,但我假设也有某种wordpress方法来加载它。

我知道我必须在函数中注册新的侧栏。php文件,但我实际上在哪里引用侧栏文件?

从文档:

name - Sidebar name (default is localized \'Sidebar\' and numeric ID).
id - Sidebar id - Must be all in lowercase, with no spaces (default is a numeric auto-incremented ID).
description - Text description of what/where the sidebar is. Shown on widget management screen. (Since 2.9) (default: empty)
class - CSS class name to assign to the widget HTML (default: empty).
before_widget - HTML to place before every widget(default: \'<li id="%1$s" class="widget %2$s">\') Note: uses sprintf for variable substitution
after_widget - HTML to place after every widget (default: "</li>\\n").
before_title - HTML to place before every title (default: <h2 class="widgettitle">).
after_title - HTML to place after every title (default: "</h2>\\n").
在这两个首选项中,您都没有指定侧栏的文件名,那么我该怎么做呢?

成功注册后,我假设可以使用get_sidebar(ID);, 这样行吗?

非常感谢您的帮助!

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

http://codex.wordpress.org/Function_Reference/get_sidebar

<?php get_sidebar(\'other\'); ?> 例如,将调用模板sidebar-other.php

您可以添加dynamic_sidebar() code 因为sidebar-other.php 样板

另请参见http://codex.wordpress.org/Widgetizing_Themes

结束

相关推荐

Adding content to sidebars

我正在设计一个三栏布局,根据主栏中的帖子/页面,所有三栏都有不同的内容。我如何才能改变和更新侧边栏内容,并使用以下内容在模板中显示它<?php the_content() ?> ? 由于侧边栏内容与帖子相关,我需要一种方法来引用帖子的右侧侧边栏内容。提前感谢诚挚的nav