WP页面加入自定义侧边栏

        在前面一篇文章中简要介绍了如何创建wordpress自定义页面,在此,介绍一下在自定义页面中加入个性化的侧边栏(sidebar.php),顶部(header.php)及底部(footer.php)。关于如何创建自定义页面,可参考此文:自定义WordPress的页面模板
下面以侧边栏为例:

我们知道在page.php(页面模板),single.php(文章模板),调用头部侧边底部的方法分别是:get_header(),get_sidebar(),get_footer(),在get_sidebar()方法中,有一段代码:

function get_sidebar( $name = null ) {
do_action( ‘get_sidebar’, $name );
$templates = array();
if ( isset($name) )
$templates[] = “sidebar-{$name}.php”;
$templates[] = “sidebar.php”;

……

所以,我们只需要建一个以sidebar.php为母版的个性化sidebar-{YourName}.php文件,在页面模板的调用中将默认get_sidebar()修改为get_sidebar(“YourName”)即可。

同理你也可以按此方法,自定义自己的header.php,footer.php 。
本站的一个搜索页面示例:点击浏览.

可能有关的文章:

Tags : , , ,

Google Reader Yahoo Facebook Twitter Digg FriendFeed Delicious Google Translate
这篇日志发表于2009年07月8日 2:39 上午。 你可以订阅该日志的所有评论通过 RSS 2.0。 你可以发表评论,或者引用通告

发表评论

Anti-Spam Protection by WP-SpamFree

(Ctrl+Enter)

XHTML:你可以使用这些标签:<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>