<?php
if (! function_exists ( 'dynamic_sidebar' ) || ! dynamic_sidebar ( 'Second_sidebar' )) :
?>
<h4>最新文章</h4>
<ul>
<?php
$posts = get_posts ( 'numberposts=6&orderby=post_date' );
foreach ( $posts as $post ) {
setup_postdata ( $post );
echo '<li><a href="' . get_permalink () . '">' . get_the_title () . '</a></li>';
}
$post = $posts [0];
?>
</ul>
<?php endif; ?>
<?php
if (! function_exists ( 'dynamic_sidebar' ) || ! dynamic_sidebar ( 'Third_sidebar' )) :
?>
<h4>标签云</h4>
<p><?php wp_tag_cloud('smallest=8&largest=22'); ?></p>
<?php endif; ?>
<?php
if (! function_exists ( 'dynamic_sidebar' ) || ! dynamic_sidebar ( 'Fourth_sidebar' )) :
?>
<h4>文章存档</h4>
<ul>
<?php wp_get_archives('limit=10'); ?>
</ul>
<?php endif; ?>
</div>
<?php
/*
同时在主题目录下创建 functions.php 文件内容为
*/
/** widgets */
if( function_exists('register_sidebar') ) {
register_sidebar(array(
'name' => 'First_sidebar', //name就是给widget指定各自的名称,以便在sidebar.php中分别调用.所以只需要给这两个widget取两个名字就好了。
'before_widget' => '', //定义Widget内容的前后标识符的语句
'after_widget' => '',
'before_title' => '<h4>', //定义Widget标题的前后标识符的语句
'after_title' => '</h4>'
));
register_sidebar(array(
'name' => 'Second_sidebar',
'before_widget' => '',
'after_widget' => '',
'before_title' => '<h4>',
'after_title' => '</h4>'
));
register_sidebar(array(
'name' => 'Third_sidebar',
'before_widget' => '',
'after_widget' => '',
'before_title' => '<h4>',
'after_title' => '</h4>'
));
register_sidebar(array(
'name' => 'Fourth_sidebar',
'before_widget' => '',
'after_widget' => '',
'before_title' => '<h4>',
'after_title' => '</h4>'
));
}
/*
这样WordPress后台 -> 外观 -> 小工具,就可以正常地拖动小工具到侧边栏了