Subcategories of wikipedia pages

Go To


Is there a way we can get all the subcategories of some category? I mean to say if I want to store only pages of category Computer Science and all its subcategories. I hope I am clear enough.

2012-04-04 03:12
by user1276381


Subcategories in MediaWiki are simply categories which are members of another category -- they're no different than articles in that regard, so you can look them up by searching for category members which are also categories. For instance, here is an API query which finds subcategories of Category:Dogs. (Namespace 14 is the category namespace.)

Note that this means that there is no guarantee that categories form a hierarchical tree! In fact, they often do not -- many categories are members of multiple other categories, and loops often exist surrounding abstract topics. For instance:

2012-04-04 03:40
by duskwuff
You're right that loops do exist, but they shouldn't. They are just errors - svick 2012-04-04 09:11
Errors or not, they make unlimited depth subcategory traversal impractical - Tgr 2012-04-04 20:10
I don't think they're errors. This blog post explains a lot: (unfortunately, there doesn't seem to be a right way to do this, though) - erickrf 2012-05-09 22:52
Think of categories as tags, not hierarchy. Some tags just happen to have other tags applied to them. This doesn't imply any overarching structure, it just means that there's some sort of relationship between the two - duskwuff 2012-05-10 00:13