迟早会来 發表於 2023-9-14 00:00:00

wordpress wp_list_categories(分类的链接列表)的使用方法

<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
<strong>1.用分类做为导航拦</strong> <br>
&lt;?php wp_list_categories('depth=2&amp;title_li=0&amp;orderby=name&amp;show_count=0');?&gt; <br>
把这句加到header.php里的nav中,我的页面如下 <br>
 </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";'>
<div 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>
</div>
<p>
代码如下:</p>
</div>
<div id="phpcode2" 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;nav&gt; <br>
&lt;div id="navDiv"&gt; <br>
&lt;ul id="nav"&gt; <br>
&lt;li&lt;?php if(is_home()) echo '' ?&gt;&gt;&lt;a href="&lt;?php bloginfo('url'); ?&gt;/"&gt;首页&lt;/a&gt;&lt;/li&gt; <br>
&lt;?php //wp_list_pages('title_li=&amp;depth=1&amp;include='); ?&gt; <br>
&lt;?php wp_list_categories('depth=2&amp;title_li=0&amp;orderby=name&amp;show_count=0');?&gt; <br>
&lt;/ul&gt; <br>
&lt;/div&gt; <br>
&lt;/nav&gt; </div>
<p>
<br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>原本是以page做为导航的,现在注掉,换用分类category来做导航 </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><strong style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>2.下面说说wp_list_categories的用法</strong><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;'>wp_list_categories 用来显示所有分类的链接列表,两种表示方法:list_cats()(deprecated) 和 wp_list_cats()(deprecated). </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>&lt;?php wp_list_categories('参数'); ?&gt; </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>默认参数设置为: </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";'>
<div 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>
</div>
<p>
代码如下:</p>
</div>
<div id="phpcode3" 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;?php $args = array( <br>
'show_option_all' =&gt; '',//不列出分类链接 <br>
'orderby' =&gt; 'name',//按照分类名排序 <br>
'order' =&gt; 'ASC',//升序排列 <br>
'style' =&gt; 'list',//列表显示分类 <br>
'show_count' =&gt; 0,//不显示分类日志数量 <br>
'hide_empty' =&gt; 1,//不显示没有日志的分类 <br>
'use_desc_for_title' =&gt; 1,//显示分类描述 <br>
'child_of' =&gt; 0,//不限制子分类 <br>
'feed' =&gt; '',//不显示feed <br>
'feed_type' =&gt; '',//不显示feed类别 <br>
'feed_image' =&gt; '',//不显示feed图片 <br>
'exclude' =&gt; '',//不显示该分类 <br>
'exclude_tree' =&gt; '',//不显示该分类树 <br>
'include' =&gt; '', <br>
'hierarchical' =&gt; 1,//分层次显示父/子分类 <br>
'title_li' =&gt; __( 'Categories' ),//用“Categories”为当前分类列表的标题 <br>
'show_option_none' =&gt; __('No categories'), <br>
'number' =&gt; null, <br>
'echo' =&gt; 1,//显示(echos) 分类 <br>
'depth' =&gt; 0,//不限制列表深度 <br>
'current_category' =&gt; 0, <br>
'pad_counts' =&gt; 0, <br>
'taxonomy' =&gt; 'category', <br>
'walker' =&gt; null <br>
); ?&gt; </div>
<p>
<br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>具体看http://codex.wordpress.org/Template_Tags/wp_list_categories </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><strong style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>3.登录登出注册</strong><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;'>if (is_user_logged_in() 为判定是否登录 </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>wp_login_url()函数---------登录超链接 </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>wp_logout_url()函数--------登出超链接 </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>&lt;a href=”&lt;?php echo wp_logout_url(); ?&gt;”&gt;logout&lt;/a&gt; </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>&lt;a href=”&lt;?php echo wp_login_url(); ?&gt;”&gt;login&lt;/a&gt; </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>如果仅是登录,登出的简单字,直接写&lt;?php wp_loginout(); ?&gt; </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;'>&lt;?php wp_register( $before, $after ); ?&gt; </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;'>其中$before(字符串)(可选)注册链接或网站管理链接前所显示的文本。默认值: '&lt;li&gt;' </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>$after(字符串)(可选)注册链接或网站管理链接后所显示的文本。默认值: '&lt;/li&gt;' </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>before参数与after参数中没有需要显示的文字&lt;?php wp_register('', ''); ?&gt;</span></p>
頁: [1]
查看完整版本: wordpress wp_list_categories(分类的链接列表)的使用方法