Widget:CategoryPages: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
| Line 28: | Line 28: | ||
;category | ;category | ||
:The name of the category. | :The name of the category. | ||
[[Category:Widgets]] | |||
</noinclude> | </noinclude> | ||
Revision as of 00:48, 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.
- category
- The name of the category.