Toggle menu
Toggle preferences menu
Toggle personal menu
Et ole kirjautunut
Your IP address will be publicly visible if you make any edits.

Moduuli:ListCategoryPages

Sarastus Wikistä
Versio hetkellä 11. joulukuuta 2024 kello 23.46 – tehnyt Virankannos (keskustelu | muokkaukset) (Ak: Uusi sivu: local p = {} function p.listPagesInCategory(frame) -- Name of the category to list pages from local categoryName = frame.args.category or "ExampleCategory" -- Ensure the category starts with "Category:" if not categoryName:match("^Category:") then categoryName = "Category:" .. categoryName end -- Get the category object local category = mw.title.new(categoryName) if not category or not category.exists then return "The cat...)
(ero) ← Vanhempi versio | Nykyinen versio (ero) | Uudempi versio → (ero)

Tämän moduulin ohjeistuksen voi tehdä sivulle Moduuli:ListCategoryPages/ohje

local p = {}

function p.listPagesInCategory(frame)
    -- Name of the category to list pages from
    local categoryName = frame.args.category or "ExampleCategory"
    
    -- Ensure the category starts with "Category:"
    if not categoryName:match("^Category:") then
        categoryName = "Category:" .. categoryName
    end

    -- Get the category object
    local category = mw.title.new(categoryName)
    if not category or not category.exists then
        return "The category does not exist."
    end

    -- Fetch all pages in the category
    local pages = category:categoryMembers()
    local result = {}

    for pageTitle, _ in pairs(pages) do
        table.insert(result, pageTitle)
    end

    -- Sort the result alphabetically
    table.sort(result)

    -- Format the output as a bulleted list
    local output = ""
    for _, title in ipairs(result) do
        output = output .. "* [[" .. title .. "]]\n"
    end

    return output
end

return p