当前位置:首页 »“秋了秋”个人博客 » WP教程 » WP内置函数参数介绍

WP内置函数参数介绍

作者:秋了秋 发表时间:2014年12月27日

在使用wp函数标签的时候,我们往往忽略了标签下还有一些参数可供设置。平时我们制作简单的博客主题只是调用一些默认的参数就能够满足需要,但是在做一些较为复杂的主题的时候,往往自定义性非常强,需要我们手动自行设置字符串参数以达到我们的需要。现在秋叶就把这些参数挖出来以便在日后能够用到。

1.输出页面函数,默认的调用函数为:<?php wp_list_pages(); ?>,参数是放在括号里面的,这样调用的默认参数有: $defaults = array( 'depth' => 0, 显示所有页面和子页面(无深度限制) 'show_date' => '', 不显示创建日期 'date_format' => get_option('date_format'), 'child_of' => 0, 子页面无限制 'exclude' => '', 不删除任何页面 'title_li' => __('Pages'), 页面列表的标题为“Pages(页面)” 'echo' => 1, 回显(显示)结果 'authors' => '', 不局限于特定作者 'sort_column' => 'menu_order, post_title', 先按页面顺序再按页面标题排序 'link_before' => '', 'link_after' => '', 'exclude_tree'=> '' );不删除父级/子级树

如果自定义参数的话,需要把参数写进括号里面,例如: <?php wp_list_pages('sort_column=menu_order&title_li=&depth=2&include=7,13,26,35'); ?>


 

2.<?php wp_list_categories() ?>用来显示所有分类的链接列表,默认参数有: <?php $args = array( 'show_option_all' => '',//不列出分类链接 'orderby' => 'name',//按照分类名排序 'order' => 'ASC',//升序排列 'style' => 'list',//列表显示分类 'show_count' => 0,//不显示分类日志数量 'hide_empty' => 1,//不显示没有日志的分类 'use_desc_for_title' => 1,//显示分类描述 'child_of' => 0,//不限制子分类 'feed' => '',//不显示feed 'feed_type' => '',//不显示feed类别 'feed_image' => '',//不显示feed图片 'exclude' => '',//不显示该分类 'exclude_tree' => '',//不显示该分类树 'include' => '', 'hierarchical' => 1,//分层次显示父/子分类 'title_li' => __( 'Categories' ),//用“Categories”为当前分类列表的标题 'show_option_none' => __('No categories'), 'number' => null, 'echo' => 1,//显示(echos) 分类 'depth' => 0,//不限制列表深度 'current_category' => 0, 'pad_counts' => 0, 'taxonomy' => 'category', 'walker' => null ); ?> 带参数调用方法:<?php wp_list_categories('title_li=0&orderby=name&show_count=0&depth=2'); ?>


 

3.<?php wp_get_archives();?>该标签显示一个基于日期的存档列表。参数变量以查询字符串形式传递给该标签。默认参数有: <?php $args = array( ’type’ => ’monthly’, ’limit’ => , ‘format’ => ‘html’, ‘before’ => , ’after’ => , ‘show_post_count’ => false, ‘echo’ => 1 ); ?> 带参数调用方法:<?php wp_get_archives(‘type=monthly&format=html&show_post_count=true’); ?>


 

4.<?php wp_tag_cloud(”); ?>输出标签云内置函数。默认参数有: <?php $args = array( 'smallest' => 8, 'largest' => 22, 'unit' => 'pt', 'number' => 45, 'format' => 'flat', 'separator' => "\n", 'orderby' => 'name', 'order' => 'ASC', 'exclude' => null, 'include' => null, 'topic_count_text_callback' => default_topic_count_text, 'link' => 'view', 'taxonomy' => 'post_tag', 'echo' => true, 'child_of' => null(see Note!) ); ?>

带参数调用方法: <?php wp_tag_cloud(‘number=50&orderby=count&order=DESC&smallest=12&largest=12&unit=px’); ?>


 

5.输出友情链接函数:<?php wp_list_bookmarks( $args ); ?>默认参数有: <?php $args = array( 'orderby' => 'name', 'order' => 'ASC', 'limit' => -1, 'category' => ' ', 'exclude_category' => ' ', 'category_name' => ' ', 'hide_invisible' => 1, 'show_updated' => 0, 'echo' => 1, 'categorize' => 1, 'title_li' => __('Bookmarks'), 'title_before' => '<h2>', 'title_after' => '</h2>', 'category_orderby' => 'name', 'category_order' => 'ASC', 'class' => 'linkcat', 'category_before' => '<li id=%id class=%class>', 'category_after' => '</li>' ); ?>

带参数调用方法: <?php wp_list_bookmarks('categorize=0&category=2&before=<span>&after=</span>&show_images=1&show_description=0&orderby=url'); ?> 意为:显示ID为2的链接分类下的所有链接,使用链接图片,不显示链接说明,按URL排列链接。

这只是一部分比较常用的,还有更多请参照wp官方文档。

0
文章作者: “秋了秋”个人博客,本站鼓励原创。
转载请注明本文地址:http://netblog.cn/blog/232.html
目录: WP教程标签: wp参数详解 8547次阅读

请求播放音乐,请点击播放

登 录
点击获取验证码
还没账号?点击这里