1.在header.php中添加下面的代码,或者也可以单独写进一个js文件中然后在header.php中引入也可以。我是引入的。
	
<script type="text/javascript">
 jQuery(document).ready(function(jQuery) {
 jQuery('.collapseButton').click(function() {
 jQuery(this).parent().parent().find('.xContent').slideToggle('slow');
 });
 });
</script>
2.在function.php中加入下面的代码:
	
 //展开收缩功能
function xcollapse($atts, $content = null){
 extract(shortcode_atts(array("title"=>""),$atts));
 return '<div style="margin: 0.5em 0;">
 <div class="xControl">
 <span class="xTitle">'.$title.'</span> 
 <a href="javascript:void(0)" class="collapseButton xButton">展开/收缩</a>
 <div style="clear: both;"></div>
 </div>
 <div class="xContent" style="display: none;">'.$content.'</div>
 </div>';
}
add_shortcode('collapse', 'xcollapse');
3.可以优化一下代码,因为默认是靠左的,不好看,我们让他往中间一点显示,具体的距离可以自行调整。当然这一步忽略也是可以的。在style.css中添加以下代码:
	
.xControl {
padding-left: 32px;
}
    







发表评论: