这个貌似用到的博客挺多的,像我的博客就有用到了这种效果,好处是比较省地方,侧栏太长影响和谐啊,这个东西还挺不错的,其实实现起来挺简单的,下面来说下代码实现这种效果的方法,供大家参考下!
其实这个不仅可以用于侧栏,底栏,头部都没有问题的,只需要稍微调整下格式即可,下面通过示例说下实现的方法!
首先:在需要他显示的地方加入以下代码,如下:
1 2 3 4 5 6 7 8 |
<div class="widget_tabcontent"> <h3><span class="selected">最新文章</span> <span>最热文章</span> <span>随机文章</span></h3> <ul>插入要调用的函数</ul> <ul class="hide">插入要调用的函数</ul> <ul class="hide">插入要调用的函数</ul> </div> |
其次:引入加载JS文件,这个挺小的,直接贴代码,适当的位置调用即可,代码如下:
1 2 3 4 5 6 7 8 9 10 |
<script type="text/javascript">
jQuery(document).ready(function($){
//注意要用这个把jQuery代码都包裹起来,不然里面的可都是无效的哦~
$('.widget_tabcontent h3 span').click(function(){
$(this).addClass("selected").siblings().removeClass();
$(".widget_tabcontent > ul").slideUp('1500').eq($('.widget_tabcontent h3
span').index(this)).slideDown('1500');
});
});
</script>
|
注意:默认的是点击切换特效,如果喜欢,也可以改成鼠标移动指向自动切换的,将click(function()中的click改成mouseover即可,显示方式修改slideUp/slideDown即可!
最后,又是老生常谈的并且让人头疼的CSS样式,提供一小段,自己参详吧!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
.widget_tabcontent h3 span
{
cursor:pointer;
padding-bottom:4px;
}
.widget_tabcontent h3 span:hover
{
color:#D54E21;
}
.selected
{
color:#D54E21;
border-bottom:1px solid #D54E21;
}
/*标题被选中时的样式*/
.widget_tabcontent .hide
{
display:none;
}
/*默认让第一块内容显示,其余隐藏*/
.widget_tabcontent ul li:hover
{
background-color:#EEE;
border-radius:5px;
-webkit-border-radius:5px;
-moz-border-radius:5px;
-khtml-border-radius:5px;
cursor:pointer;
}
|
下面给出一些常用的调用文章代码,大家可以根据需要插入到适当的位置就好了:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
热门文章: <?php query_posts(array('posts_per_page' => 10, 'caller_get_posts' =>1,'orderby' =>comment_count,)); while ( have_posts() ) : the_post(); ?> <li><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a></li> <?php endwhile;wp_reset_query();?> 最新文章: <?php query_posts(array('posts_per_page' => 10, 'caller_get_posts' =>1,'orderby' =>date,)); while ( have_posts() ) : the_post(); ?> <li><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a></li> <?php endwhile;wp_reset_query();?> 随机文章: <?php query_posts(array('posts_per_page' => 10, 'caller_get_posts' =>1,'orderby' =>rand,)); while ( have_posts() ) : the_post(); ?> <li><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a></li> <?php endwhile;wp_reset_query();?> |
收下了,谢谢分享!
不过还是喜欢你原来的主题
是的。我在升级里也打算用。