Widgets是一个可视化Wordpress主题侧边栏编辑插件,用户可以在Wordpress后台主题配置里面,通过拖曳相应模块到侧边栏来自定义侧边栏内容显示。具体使用说明,详见本人另外一篇文章:Widgets 1.21中文版及使用说明(附图) 

只需在主题文件里面加入适当代码,就可以让主题支持widget拖曳。

1. 修改functions.php代码

如果该主题有functions.php,请在<?php 代码后中加入: 

if ( function_exists(‘register_sidebars’) )

register_sidebars();

如果没有functions.php文件,请建立一个functions.php文件,并输入如下4行代码: 

<?php

if ( function_exists(‘register_sidebars’) ) 

register_sidebars();

?>

注意,如果侧边栏数量大于1,请在register_sidebars()的()中输入具体数量。例,侧边栏的数目为2,代码为register_sidebars(2); 

2.2 修改侧边栏代码

在主题文件中找到侧边栏定义代码,例如:

<div id=”sidebar”> 

…侧边栏内容

</div>

 

<?php if ( function_exists(‘dynamic_sidebar’) && dynamic_sidebar() ) : else : ?>

<?php endif; ?>

代码嵌套在sidebar的<div>标签里面即可。 

<div id=”sidebar”>

<?php if ( function_exists(‘dynamic_sidebar’) && dynamic_sidebar() ) : else : ?>

…侧边栏内容 

<?php endif; ?>

</div>

侧边栏的数目为2的时候,要分别定义。例: 

<div id=”sidebar1″>

<?php if ( function_exists(‘dynamic_sidebar’) && dynamic_sidebar(1) ) : else : ?>
…侧边栏内容

<?php endif; ?> 

</div>

<div id=”sidebar2″>

<?php if ( function_exists(‘dynamic_sidebar’) && dynamic_sidebar(2) ) : else : ?>
…侧边栏内容 

<?php endif; ?>

</div>

注意:dynamic_sidebar()括号里面内容要各个侧边栏相对应。默认Widget中的样式,标题是h2格式,内容以<ul>和<li>标签嵌套。  

Feed Me


转载文章请注明转载自:ThinkAgain - Let's Blog!

引用地址:http://www.thinkagain.cn/archives/161.html