Module:NewsLanding/Slider

From TwogPedia
< Module:NewsLanding
Revision as of 06:24, 18 February 2024 by Couchor (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Documentation for this module may be created at Module:NewsLanding/Slider/doc

local getArgs = require('Module:Arguments').getArgs
local cargo = mw.ext.cargo

local p = {}

function p.main(frame)
	local tables = 'News'
	local fields = '_pageName, date, image'
	local cargoArgs = {
		orderBy = 'date DESC',
		limit = 5,
	}
	local results = cargo.query(tables, fields, cargoArgs)
	
	local container = mw.html.create('div'):attr('id', 'news-slider-container')
	
	if #results > 0 then
		for i = 1, #results do
			local result = results[i]
			
            local title = mw.html.create('div'):addClass('news-title'):wikitext(mw.ext.displaytitle.get(result._pageName))
			local image = result.image or 'News placeholder.png'
			local newsItem = mw.html.create('div'):addClass('news-item'):wikitext('[[File:'.. image .. '|link=' .. result._pageName .. ']]'):node(title)
			container:node(newsItem)
		end
		return container
	end
end

return p