Widget:CategoryPages: Difference between revisions
Jump to navigation
Jump to search
mNo edit summary |
No edit summary |
||
| Line 24: | Line 24: | ||
</script> | </script> | ||
<noinclude> | <noinclude> | ||
This widget uses the MediaWiki API to request a list of pages within a category, and spits them out into a div. It takes one parameter, which is the category name. | This widget uses the MediaWiki API to request a list of pages within a category, and spits them out into a div. It takes one parameter, which is the category name. This is done on the client side, using JavaScript, which is less than ideal. | ||
==Example== | |||
<nowiki>{{#widget:CategoryPages|category=Tools and Equipment in Electronics Area}}</nowiki> | |||
{{#widget:CategoryPages|category=Tools and Equipment in Electronics Area}} | |||
==Parameters== | |||
;category | ;category | ||
:The name of the category. | :The name of the category. | ||
[[Category:Widget]] | [[Category:Widget]] | ||
</noinclude> | </noinclude> | ||
Revision as of 00:59, 24 January 2025
<script type="text/javascript">
(function() {
const url = '/api.php?action=query&list=categorymembers&cmtitle=Category:&format=json&cmlimit=40';
fetch(url).then(function(response) {
return response.json();
}).then(function(data) {
const wrapper = document.getElementById('categoryPages');
const pages = data.query.categorymembers;
for (const pageIdx in pages) {
const page = pages[pageIdx];
const pageLink = document.createElement('a');
pageLink.href = `/index.php?curid=${page.pageid}`;
pageLink.appendChild(document.createTextNode(page.title));
wrapper.appendChild(pageLink);
if (pageIdx < (pages.length - 1)) {
wrapper.appendChild(document.createTextNode(' • '));
}
}
}).catch(function(err) {
console.log('Fetch Error :-S', err);
});
})();
</script>
This widget uses the MediaWiki API to request a list of pages within a category, and spits them out into a div. It takes one parameter, which is the category name. This is done on the client side, using JavaScript, which is less than ideal.
Example
{{#widget:CategoryPages|category=Tools and Equipment in Electronics Area}}
Parameters
- category
- The name of the category.