一个字“简单”!
首先:在需要他显示的地方加入以下代码,如下:
<div> <h3><span>最新文章</span> <span>最热文章</span> <span>随机文章</span></h3> <ul>插入要调用的函数</ul> <ul>插入要调用的函数</ul> <ul>插入要调用的函数</ul> </div>
其次:引入加载JS文件,这个挺小的,直接贴代码,适当的位置调用即可,代码如下:
<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样式,提供一小段,自己参详吧!
.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;
}
下面给出一些常用的调用文章代码,大家可以根据需要插入到适当的位置就好了:
热门文章:
<?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();?>
声明:本文采用 BY-NC-SA 协议进行授权,如无注明均为原创,转载请注明转自 你好!刘
本文地址:WordPress,侧栏等地方非插件实现Tab切换的效果代码分享
本文地址:WordPress,侧栏等地方非插件实现Tab切换的效果代码分享
发表评论