wordpress开发:is_active_sidebar(),侧边栏小工具判断函数

2018-10-1910:38:51网站建设与开发Comments2,101 views字数 553阅读模式

is_active_sidebar()函数的作用是检测指定的侧边栏小工具是否在使用并返回结果,正在使用就返回true,没有使用就返回false。比如存在ID分别为sidebar-1、sidebar-2、sidebar-3三个侧边位,要判断sidebar-1的侧边栏中是否存在小工具就可以使用wordpress函数is_active_sidebar()文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/6831.html

函数代码

1
<?php is_active_sidebar( $index ); ?>
参数说明

$index – 侧边栏的名称或者id,默认值:None文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/6831.html

返回值

布尔型(boolean),如果侧边栏在使用返回true,否则返回false文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/6831.html

示例

根据侧边栏是否被使用而显示不同的内容文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/6831.html

1
2
3
4
5
6
7
8
9
<?php if(is_active_sidebar('left-sidebar')){ ?>
	<ul id="sidebar">
		<?php dynamic_sidebar('left-sidebar'); ?>
	</ul>
<?php }else{ ?>
	<div class="textwidget">
		<p>广告位待租!</p>
	</div>
<?php } ?>

注:left-sidebar是侧边栏ID文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/6831.html

源文件

is_active_sidebar()函数位置:wp-includes/widgets.php.文章源自菜鸟学院-https://www.cainiaoxueyuan.com/cms/6831.html

  • 本站内容整理自互联网,仅提供信息存储空间服务,以方便学习之用。如对文章、图片、字体等版权有疑问,请在下方留言,管理员看到后,将第一时间进行处理。
  • 转载请务必保留本文链接:https://www.cainiaoxueyuan.com/cms/6831.html

Comment

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定