API:Categories
Jump to navigation
Jump to search
| Categories | ||
|---|---|---|
| List all categories the page(s) belong to. This module can be used as a Generator. |
||
| Prefix | cl | |
| Required rights | none | |
| Post only? | No | |
| Generated help | Current | |
| Version added |
|
|
Gets a list of all categories used on the provided pages. This module can be used as a generator.
Contents
Parameters[edit]
clprop: Which properties to get.sortkey: The sort key.timestamp: The date and time the page was added to the category, or the date and time its sortkey was changed last. 1.13+- : Whether the category is hidden or not. 1.16+
clshow: Which kinds of categories to list. Conflicting options (such ashiddenand!hidden) cannot be used together. 1.14+- : Only list hidden categories.
- : Don't list hidden categories.
cllimit: Maximum number of results to return. 1.13+clcontinue: When more results are available, use this to continue. 1.13+clcategories: Only list these categories. Useful to check whether a certain page is in a certain category. Note: This parameter takes full titles, so the Category: prefix must be used. 1.15+cldir: The direction in which to list. Possible values:ascending,descending. (Default:ascending) 1.20+
Example[edit]
Get a list of categories en:Albert Einstein belongs to
| Result |
|---|
{
"continue": {
"clcontinue": "736|American_Zionists",
"continue": "||"
},
"query": {
"pages": {
"736": {
"pageid": 736,
"ns": 0,
"title": "Albert Einstein",
"categories": [
{
"ns": 14,
"title": "Category:1879 births"
},
{
"ns": 14,
"title": "Category:1955 deaths"
},
{
"ns": 14,
"title": "Category:20th-century American engineers"
},
{
"ns": 14,
"title": "Category:20th-century American writers"
},
{
"ns": 14,
"title": "Category:20th-century German writers"
},
{
"ns": 14,
"title": "Category:20th-century Jews"
},
{
"ns": 14,
"title": "Category:20th-century physicists"
},
{
"ns": 14,
"title": "Category:AC with 19 elements"
},
{
"ns": 14,
"title": "Category:Activists from New Jersey"
},
{
"ns": 14,
"title": "Category:Albert Einstein"
}
]
}
}
}
}
|
Possible errors[edit]
| Code | Info |
|---|---|
| clshow | Incorrect parameter - mutually exclusive values may not be supplied |
| The following documentation is the output of Special:ApiHelp/query+categories, automatically generated by the pre-release version of MediaWiki that is running on this site (MediaWiki.org). |
prop=categories (cl)
- This module requires read rights.
- This module can be used as a generator.
- Source: MediaWiki
- License: GPL-2.0-or-later
List all categories the pages belong to.
Parameters:
- clprop
Which additional properties to get for each category:
- sortkey
- Adds the sortkey (hexadecimal string) and sortkey prefix (human-readable part) for the category.
- timestamp
- Adds timestamp of when the category was added.
- hidden
- Tags categories that are hidden with
__HIDDENCAT__.
- Values (separate with | or alternative): sortkey, timestamp, hidden
- clshow
Which kind of categories to show.
- Values (separate with | or alternative): hidden, !hidden
- cllimit
How many categories to return.
- No more than 500 (5,000 for bots) allowed.
- Type: integer or max
- Default: 10
- clcontinue
When more results are available, use this to continue.
- clcategories
Only list these categories. Useful for checking whether a certain page is in a certain category.
- Separate values with | or alternative. Maximum number of values is 50 (500 for bots).
- cldir
The direction in which to list.
- One of the following values: ascending, descending
- Default: ascending
Examples:
- Get a list of categories the page Albert Einstein belongs to.
- api.php?action=query&prop=categories&titles=Albert%20Einstein [open in sandbox]
- Get information about all categories used in the page Albert Einstein.
- api.php?action=query&generator=categories&titles=Albert%20Einstein&prop=info [open in sandbox]