开发者 | coffee2code |
---|---|
更新时间 | 2024年8月29日 06:04 |
捐献地址: | 去捐款 |
PHP版本: | 4.6 及以上 |
WordPress版本: | 6.6 |
版权: | GPLv2 or later |
版权网址: | 版权信息 |
the_category()
. the_category()
lists all categories directly assigned to the specified post. c2c_parentless_categories()
lists those categories, except for categories that are parents to other assigned categories.
For example, assume your category structure is hierarchical and looks like this:
Vegetables |-- Leafy | |-- Broccoli | |-- Bok Choy | |-- Celery |-- Fruiting | |-- Bell Pepper | |-- Cucumber | |-- Pumpkin |-- Podded | |-- Chickpea | |-- Lentil | |-- Soybean
If you directly assigned the categories "Fruiting", "Cucumber", and "Pumpkin" to a post, c2c_parentless_categories()
would return a list that consists of: "Cucumber", and "Pumpkin". Notice that since "Fruiting" was a parent to a directly assigned category, it is not included in the list.
By default, categories are listed as an HTML list. The first argument to the template tag allows you to define a custom separator, e.g. to have a simple comma-separated list of categories: <?php c2c_parentless_categories( ',' ); ?>
.
As with categories listed via the_category()
, categories that are listed are presented as links to the respective category's archive page.
Example usage (based on preceding example):
<?php c2c_parentless_categories(); ?>
*
<?php c2c_parentless_categories( ',' ); ?>`
Outputs something like:
<a href="http://yourblog.com/category/fruiting/cucumber">Cucumber</a>, <a href="http://yourblog.com/category/fruiting/pumpkin">Pumpkin</a>
Links: Plugin Homepage | Plugin Directory Page | GitHub | Author Homepage
/wp-content/plugins/
).<?php c2c_parentless_categories(); ?>
in a theme template somewhere inside "the loop"c2c_parentless_categories()
listing?If an assigned category is the parent for one or more other assigned categories for the post, then the category parent is not included in the listing.
Yes. The tests are not packaged in the release .zip file or included in plugins.svn.wordpress.org, but can be found in the plugin's GitHub repository.
.gitignore
filecomposer.json
for PHPUnit Polyfill dependencybootstrap.php
c2c_parentless_categories()
parentless_categories()
, get_parentless_categories_list()
, get_parentless_categories()
), adds DEVELOPER-DOCS.md, notes compatibility through WP 5.8+, and minor reorganization and tweaks to unit tests.
Details:
parentless_categories()
, get_parentless_categories_list()
, and get_parentless_categories()
phpunit/
into tests/phpunit/
phpunit/bin/
into tests/