WordPress: Function Reference/get categories:修订间差异
来自站长百科
(新页面: == Description == Returns an array of category objects matching the query parameters. Arguments are pretty much the same as [[WordPress:Template_Tags/wp_list_categories|wp_list_categori...) |
无编辑摘要 |
||
(未显示另一用户的1个中间版本) | |||
第1行: | 第1行: | ||
== | ==描述 == | ||
返回与查询参数匹配的类别objects的数组。 | |||
参数与[[WordPress:Template_Tags/wp_list_categories|wp_list_categories]]非常相像,可以用来作为数组传递,或者在查询语法中传递。<!—返回的数组似乎总是flat (没有嵌套的子类别)但是我还不确定。--> | |||
== | == 用法 == | ||
%%% <?php $categories = get_categories(parameters); ?> %%% | %%% <?php $categories = get_categories(parameters); ?> %%% | ||
== 例子== | |||
== | ===默认用法=== | ||
%%% <?php $defaults = array('type' => 'post', | %%% <?php $defaults = array('type' => 'post', | ||
'child_of' => 0, | 'child_of' => 0, | ||
第24行: | 第24行: | ||
'pad_counts' => false);?>%%% | 'pad_counts' => false);?>%%% | ||
=== | === 下拉列表框 === | ||
下面是创建如,存档有文章记录的类别的子类别的下拉列表框。这反映了[[WordPress:Template_Tags/wp_get_archives | wp_get_archives]]下面列表的例子,[[WordPress:Template_Tags/wp_get_archives | wp_get_archives]]显示怎样为按月的存档创建下拉列表框。 | |||
假如你想要显示的子类别的上级类别是10,而且类别"昵称"是"存档"。 | |||
<pre> | <pre> | ||
<select name="event-dropdown" onchange='document.location.href=this.options[this.selectedIndex].value;'> | <select name="event-dropdown" onchange='document.location.href=this.options[this.selectedIndex].value;'> | ||
第44行: | 第45行: | ||
</pre> | </pre> | ||
== | == 参数 == | ||
; '''type''' (''string'') : | ; '''type''' (''string'') :需要返回的类别的类型 | ||
:* <tt>post</tt> - | :* <tt>post</tt> - 默认 | ||
:* <tt>link</tt> | :* <tt>link</tt> | ||
; '''child_of''' (''integer'') : | |||
; '''orderby''' (''string''): | ; '''child_of''' (''integer'') :只显示某个类别ID的子类别。这个参数没有默认设置。如果使用了这个参数,'''hide_empty'''参数设置为''false''。 | ||
:* <tt>ID</tt> - | ; '''orderby''' (''string''):根据字母表属性或者类别ID给类别分类。默认为''根据类别 ID分类''。有效的参数值: | ||
:* <tt>ID</tt> - 默认 | |||
:* <tt>name</tt> | :* <tt>name</tt> | ||
; '''order''' (''string''): | ; '''order''' (''string''):类别的分类顺序(升序或者降序)。默认为''升序''。有效的参数值: | ||
:* <tt>asc</tt> - | :* <tt>asc</tt> - 默认 | ||
:* <tt>desc</tt> | :* <tt>desc</tt> | ||
; '''hide_empty''' (''boolean''): | |||
:* <tt>1 (true)</tt> - | ; '''hide_empty''' (''boolean''): Toggles没有文章的类别的显示。默认为''正确的''(隐藏空类别)。有效的参数值: | ||
:* <tt>1 (true)</tt> - 默认的 | |||
:* <tt>0 (false)</tt> | :* <tt>0 (false)</tt> | ||
; '''include_last_update_time''' (''boolean''): | |||
; '''include_last_update_time''' (''boolean''):不确定what this doesies|the example]]。 | |||
:* <tt>1 (true)</tt> | :* <tt>1 (true)</tt> | ||
:* <tt>0 (false)</tt> -- | :* <tt>0 (false)</tt> -- 默认 | ||
; '''hierarchical''' (''boolean''): | |||
:* <tt>1 (true)</tt> - | ; '''hierarchical''' (''boolean''):将子类别显示为内嵌的列表内容(母类别下面)或者内套。默认为''true''(在母列表内容的下面显示子类别)。有效的参数值: | ||
:* <tt>1 (true)</tt> -默认的 | |||
:* <tt>0 (false)</tt> | :* <tt>0 (false)</tt> | ||
; '''exclude''' (''string''): | |||
; '''include''' (''string''): | ; '''exclude''' (''string''):从''wp_list_categories''产生的列表中删除一个或者更多的类别。这个参数有一个用逗号分开的类别ID,以升序排列。 | ||
:* <tt>list</tt> - | |||
请看看[[WordPress:Template_Tags/wp_list_categories#Include_or_Exclude_Categories|例子]]。 | |||
; '''include''' (''string''):在''wp_list_categories''产生的列表中只包含某些类别。这个参数有一个用逗号分开的类别ID的列表,以升序排列。 | |||
请看看[[WordPress:Template_Tags/wp_list_categories#Include_or_Exclude_Categories|例子]]。 | |||
:* <tt>list</tt> -默认。 | |||
:* <tt>none</tt> | :* <tt>none</tt> | ||
; '''number''' (''string'') : | ; '''number''' (''string'') : 返回的类别数字 | ||
; '''pad_counts''' (''boolean''): | ; '''pad_counts''' (''boolean''): 包含子类别的内容,技术链接或者文章字数。有效的参数值: | ||
:* <tt>1 (true)</tt> | :* <tt>1 (true)</tt> | ||
:* <tt>0 (false)</tt> - | :* <tt>0 (false)</tt> -默认 |
2008年7月25日 (五) 10:48的最新版本
描述[ ]
返回与查询参数匹配的类别objects的数组。
参数与wp_list_categories非常相像,可以用来作为数组传递,或者在查询语法中传递。<!—返回的数组似乎总是flat (没有嵌套的子类别)但是我还不确定。-->
用法[ ]
%%% <?php $categories = get_categories(parameters); ?> %%%
例子[ ]
默认用法[ ]
%%% <?php $defaults = array('type' => 'post', 'child_of' => 0, 'orderby' => 'name', 'order' => 'ASC', 'hide_empty' => true, 'include_last_update_time' => false, 'hierarchical' => 1, 'exclude' => , 'include' => , 'number' => , 'pad_counts' => false);?>%%%
下拉列表框[ ]
下面是创建如,存档有文章记录的类别的子类别的下拉列表框。这反映了 wp_get_archives下面列表的例子, wp_get_archives显示怎样为按月的存档创建下拉列表框。
假如你想要显示的子类别的上级类别是10,而且类别"昵称"是"存档"。
<select name="event-dropdown" onchange='document.location.href=this.options[this.selectedIndex].value;'> <option value=""><?php echo attribute_escape(__('Select Event')); ?></option> <?php $categories= get_categories('child_of=10'); foreach ($categories as $cat) { $option = '<option value="/category/archives/'.$cat->category_nicename.'">'; $option .= $cat->cat_name; $option .= ' ('.$cat->category_count.')'; $option .= '</option>'; echo $option; } ?> </select>
参数[ ]
- type (string)
- 需要返回的类别的类型
- post - 默认
- link
- child_of (integer)
- 只显示某个类别ID的子类别。这个参数没有默认设置。如果使用了这个参数,hide_empty参数设置为false。
- orderby (string)
- 根据字母表属性或者类别ID给类别分类。默认为根据类别 ID分类。有效的参数值:
- ID - 默认
- name
- order (string)
- 类别的分类顺序(升序或者降序)。默认为升序。有效的参数值:
- asc - 默认
- desc
- hide_empty (boolean)
- Toggles没有文章的类别的显示。默认为正确的(隐藏空类别)。有效的参数值:
- 1 (true) - 默认的
- 0 (false)
- include_last_update_time (boolean)
- 不确定what this doesies|the example]]。
- 1 (true)
- 0 (false) -- 默认
- hierarchical (boolean)
- 将子类别显示为内嵌的列表内容(母类别下面)或者内套。默认为true(在母列表内容的下面显示子类别)。有效的参数值:
- 1 (true) -默认的
- 0 (false)
- exclude (string)
- 从wp_list_categories产生的列表中删除一个或者更多的类别。这个参数有一个用逗号分开的类别ID,以升序排列。
请看看例子。
- include (string)
- 在wp_list_categories产生的列表中只包含某些类别。这个参数有一个用逗号分开的类别ID的列表,以升序排列。
请看看例子。
- list -默认。
- none
- number (string)
- 返回的类别数字
- pad_counts (boolean)
- 包含子类别的内容,技术链接或者文章字数。有效的参数值:
- 1 (true)
- 0 (false) -默认