|
Create a module in Joomla
First module will be registered in a database. Tables that will do this is jos_modules (code below will change the prefix of the database - in this tutorial will keep the code below!).
We will start this little tutorial by creating a module that displays the latest headlines Posted articles. This module will mod_lastarticle name.
To begin you will need to register the module in the database. To do this open phpMyAdmin, select the desired database, select the table jos_modules and SQL tab add the following code:
INSERT INTO jos_modules (title, ordering, position, published, module, showtitle, params) VALUES ('Last article', 1, 'left', 1, 'mod_lastarticle', 1, '');
At this point the module will not appear on the site even if in the records in the data set published = 1. We enter the admin panel, Extensions -> Module Manager and will open new module created (mod_lastarticle). When we set Assigment Menu option All and will save the module.
At this point we can check it on the first page display. If all went well before you see the module title set in the database (Last article) in the "left" the site, the first position.
Next we create a new folder in modules directory called mod_lastarticle. In this directory we will create a file mod_lastarticle.php. In this file we will add a header with license and we will check if the file is called by joomla
<?php /** * @version $Id: mod_login.php 10381 2008-06-01 03:35:53Z pasamio $ * @package Joomla * @copyright Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved. * @license GNU/GPL, see LICENSE.php * Joomla! is free software. This version may have been modified pursuant * to the GNU General Public License, and as distributed it includes or * is derivative of works licensed under the GNU General Public License or * other free or open source software licenses. * See COPYRIGHT.php for copyright notices and details. */ // no direct access defined('_JEXEC') or die('Restricted access');
The next step will be a database query to be returned to us last items added records in the database.
$db =& JFactory::getDBO(); $query = "SELECT `title` FROM #__content ORDER BY `created` DESC LIMIT 0,5"; $db->setQuery ( $query ); $rows = $db->loadObjectList(); foreach ($rows as $row) { $query = "SELECT `alias` from #__categories WHERE `id` = '".$row->catid."'"; $db->setQuery ( $query ); $rezult = $db->loadResult(); $link = JRoute::_('index.php?option=com_content&view=article&id='.$row->id.':'.$row->alias.'&catid='.$row->catid.':'.$rezult.'&Itemid=50'); echo '<a href="'.$link.'">'.$row->title.'</a><br />'; } ?>
At this time we will be this way last retunate Posted 5 items (including link to them). Then you have to create a new file called mod_lastarticle.xml. In this file we add the following code:
<?xml version="1.0" encoding="utf-8"?> <install type="module" version="1.5.0"> <name>Last article</name> <author>Numele tau aici</author> <creationDate>Noiembrie 2009</creationDate> <copyright>Copyright (C) </copyright> <license>http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL</license> <authorEmail>
This e-mail address is being protected from spambots. You need JavaScript enabled to view it
</authorEmail> <authorUrl>www.joomla.ro</authorUrl> <version>1.5.0</version> <description>Acest modul afiseaza ultimele articole adaugate pe site</description> <files> <filename module="mod_lastarticle">mod_lastarticle.php</filename> </files> </install>
At this point you can archive directory mod_lastarticle and it can provide to other users to use.
To be continued ...
|