博志 發表於 2023-9-24 00:00:00

wordpress dynamic_sidebar()函数使用方法

<p>
<span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>dynamic_sidebar()函数用来支持自定义sidebar侧边栏,可以自定义Widget插件,比如为侧边栏添加最近文章,文章归档,最新评论,标签云,搜索框,类别,链接表等。</span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>那么如何使用呢?</span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>在主题的functions.php文件的尖括号内添加形如下面的语句:</span></p>
<div style='margin: 3px auto 0px; padding: 0px 3px; outline: none; line-height: 21.6px; clear: both; border-width: 1px; border-style: solid; border-color: rgb(0, 153, 204); background: rgb(246, 251, 255); overflow: hidden; font-family: tahoma, arial, "Microsoft YaHei";'>
<p style="margin: 0px; padding: 0px; outline: none; float: right; line-height: 25.2px; font-size: 14px;">
<span style="line-height: 25.2px; cursor: pointer;"><u>复制代码</u></span></p>
<p>
代码如下:</p>
</div>
<p style='margin: 0px auto 3px; padding: 0px 3px; outline: none; line-height: 25.2px; font-size: 14px; clear: both; border-right: 1px solid rgb(0, 153, 204); background: rgb(221, 237, 251); overflow: hidden; border-left: 1px solid rgb(0, 153, 204); word-break: break-all; border-bottom: 1px solid rgb(0, 153, 204); word-wrap: break-word; font-family: tahoma, arial, "Microsoft YaHei";'>
<br>
register_sidebar(array(<br>
‘name’ =&gt; ‘Sidebar’,<br>
‘before_widget’ =&gt; ‘&lt;div class=”widget-sidebar”&gt;’,<br>
‘after_widget’ =&gt; ‘&lt;/div&gt;’,<br>
‘before_title’ =&gt; ‘&lt;h3 class=”widget-title”&gt;’,<br>
‘after_title’ =&gt; ‘&lt;/h3&gt;’<br>
));</p>
<p>
<br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>它的意思是:注册一个名为Sidebar的侧边栏,显示在”widget-sidebar”的标签内,标题的样式为h3。调用方法为:</span></p>
<div style='margin: 3px auto 0px; padding: 0px 3px; outline: none; line-height: 21.6px; clear: both; border-width: 1px; border-style: solid; border-color: rgb(0, 153, 204); background: rgb(246, 251, 255); overflow: hidden; font-family: tahoma, arial, "Microsoft YaHei";'>
<p style="margin: 0px; padding: 0px; outline: none; float: right; line-height: 25.2px; font-size: 14px;">
<span style="line-height: 25.2px; cursor: pointer;"><u>复制代码</u></span></p>
<p>
代码如下:</p>
</div>
<p style='margin: 0px auto 3px; padding: 0px 3px; outline: none; line-height: 25.2px; font-size: 14px; clear: both; border-right: 1px solid rgb(0, 153, 204); background: rgb(221, 237, 251); overflow: hidden; border-left: 1px solid rgb(0, 153, 204); word-break: break-all; border-bottom: 1px solid rgb(0, 153, 204); word-wrap: break-word; font-family: tahoma, arial, "Microsoft YaHei";'>
<br>
&lt;div id=”sidebar”&gt;<br>
&lt;?php if (!dynamic_sidebar( ‘Sidebar’ )) &gt;<br>
&lt;div&gt;<br>
&lt;h3&gt;标题&lt;/h3&gt;<br>
&lt;ul&gt;<br>
&lt;li&gt;&lt;a href=”#”&gt;文章标题&lt;/a&gt;&lt;/li&gt;<br>
&lt;li&gt;&lt;a href=”#”&gt;文章标题&lt;/a&gt;&lt;/li&gt;<br>
&lt;li&gt;&lt;a href=”#”&gt;文章标题&lt;/a&gt;&lt;/li&gt;<br>
&lt;li&gt;&lt;a href=”#”&gt;文章标题&lt;/a&gt;&lt;/li&gt;<br>
&lt;li&gt;&lt;a href=”#”&gt;文章标题&lt;/a&gt;&lt;/li&gt;<br>
&lt;li&gt;&lt;a href=”#”&gt;文章标题&lt;/a&gt;&lt;/li&gt;<br>
&lt;li&gt;&lt;a href=”#”&gt;文章标题&lt;/a&gt;&lt;/li&gt;<br>
&lt;/ul&gt;<br>
&lt;/div&gt;</p>
<p>
<br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>这样在后台小工具里面就可以设置sidebar自定义侧边栏了,增加或移除widget插件内容。假如你没有设置,那么显示你自己编辑的内容,设置了就会覆盖掉你自己编辑的内容。</span></p>
頁: [1]
查看完整版本: wordpress dynamic_sidebar()函数使用方法