为自已的wordpress添加了sidebar
为自已的wordpress添加了sidebar。实际添加方法和过程还是很简单的,虽然走了点弯路。
原来我的页面组成是这样的:
|header |
|body | second | third |
|footer |
实际上只需要把second调整成sidebar即可。
mv second.php sidebar.php,在编辑文件里就可以找到sidebar.php了,然后再创建一个functions.php文件。
sidebar.php添加出下代码:
<div id=”sidebar”>
<ul>
<?php include (TEMPLATEPATH . ‘/searchform.php’); ?>
<div>
<ul>
<?php wp_register(); ?>
<li><?php wp_loginout(); ?></li>
<?php wp_meta(); ?>
</ul>
</div>
<div>
<h2>分类</h2>
<ul>
<?php wp_list_cats(); ?>
</ul>
</div>
<?php /* Widgetized sidebar, if you have the plugin installed. */
if ( !function_exists(’dynamic_sidebar’) || !dynamic_sidebar() ) : ?>
<?php endif; ?>
</ul>
</div>
functions.php文件添加如下代码:
if ( function_exists(’register_sidebar’) ) {
register_sidebar();
}
好了,现在我的blog已经有sidebar了,可以添加一些小插件了:)
看看效果。坏了,样式变了,都乱了,怎么办?仔细想了想,是因为样式没有按second去配。
于是修改了如下代码,实际只是添了一个属性:
<?php include (TEMPLATEPATH . ‘/searchform.php’); ?>
<div”>
=>
<?php include (TEMPLATEPATH . ‘/searchform.php’); ?>
<div class=”middle_links”>
再对function进行如下修改:
register_sidebar();
=>
register_sidebar(array(
‘before_widget’ => ‘<div class=”middle_links”>’,
‘after_widget’ => ‘</div>’,
));
作用:
在每个widget开始之前加一个div 属性,内容按middle_links去显示。
再看一下效果吧,
嗯,效果一致了,不错!看起来,可能想着复杂的事情,实际做了就简单了。
thx
张久安
If you enjoyed this post, make sure you subscribe to my RSS feed!









No Comments, Comment or Ping
Reply to “为自已的wordpress添加了sidebar”
You must be logged in to post a comment.