为wordpress不同文章不同页面定制不同的侧边栏

| | Comments (2)



wordpress 默认页面固定不变的侧栏,几乎是一成不变的,自己都会看烦,利用一些技巧可以新建几个侧栏文件,然后上传到当前主题文件夹。最后----

打开single.php文件*,找到get_sidebar()函数:

<?php get_sidebar(); ?>
将其替换为:

<?php $sidebar = get_post_meta($post->ID, "sidebar", true);
get_sidebar($sidebar);
?>
之后当你需要发布新文章时,只需要新建一个叫做"sidebar"(自定义字段的名称)的自定义字段,把选定的侧栏模板文件的名称作为这个自定义字段的值。例如当字段被赋予的值是right时,WordPress就会自动调用right.php作为页面侧栏。

*同样的道理也适用于page.php,同样修改<?php get_sidebar(); ?>。

 

除了这个自定义字段的方法来加载不同的侧边栏,也可以利用wordpress条件标签使不同目录或者tag内的文章加载不同页脚、侧边拦、页头(header)等,相关操作请参考(WordPress网站开发常用条件标签列表


单点日志http://spoint.babyshoot.cn/

2 Comments

你的GG广告字有点显眼,鼓励你的文章帮你点了下GG广告。

感激阿,你贡献很大,一个月也就3次点击,你都占30%了

Leave a comment

Archives

Ads by google

Pages

Powered by Movable Type 4.24-en

About this Entry

This page contains a single entry by 单点日志 published on June 17, 2010 12:39 PM.

2010年 端午节-端午节的来历和风俗介绍 was the previous entry in this blog.

2010世界杯:珍惜生命,远离国足!哥们,今天你看球了么? is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.