WordPress侧栏等处所非插件实现Tab切换的结果代码分享

  这个貌似用到的博客挺多的,像我的博客就有用到了这种结果,长处是较量省处所,侧栏太长影响调和啊,这个对象还挺不错的,其实实现起来挺简朴的,下面来说下代码实现这种结果的要领,供各人参考下。

  其实这个不只可以用于侧栏、底栏、头部都没有问题的,只需要稍微调解下名目即可,下面通过示例说下实现的要领。

  首先,在需要他显示的处所插手以下代码,如下:

<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文件,这个挺小的,直接贴代码,适当的位置挪用即可,代码如下:

<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=http://down.chinaz.com/"<?php the_permalink() ?>" rel="bookmark"
title=http://down.chinaz.com/"<?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=http://down.chinaz.com/"<?php the_permalink() ?>" rel="bookmark"
title=http://down.chinaz.com/"<?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=http://down.chinaz.com/"<?php the_permalink() ?>" rel="bookmark"
title=http://down.chinaz.com/"<?php the_title(); ?>"><?php the_title(); ?></a></li>
<?php endwhile;wp_reset_query();?>

Wordpress下载:

WordPress v3.5.2 简体中文版下载

WordPress侧栏等地方非插件实现Tab切换的功效代码分享

界面预览

WordPress v4.4.2 英文版下载

WordPress侧栏等地方非插件实现Tab切换的功效代码分享

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/10272.html