Sunday, 24 October 2010 07:41

Creating Joomla module title links

Written by Miguel
questionthought

Ever wanted to turn the title of a module into a hyperlink?

For this example, I will be using the mod_mainmenu module.

First, we add the necessary parameters to the module XML file, in order to input the link URL through the module manager:

 

1.       Open the file modules/mod_mainmenu/mod_mainmenu.xml

2.       Add the following line between the first set of <params></params> tags,

<param type="text" default="" label="Title link URL" description="PARAMLINKURL" />

3.       Save and upload the XML file.

 

Now you should be able to see the new parameter entitled Title link URL, in the module parameter settings. Insert your URL into the input field and save.

 

Next, create a folder in your template folder and name it html. Copy the file templates/system/html/modules.php, to your template directory (templates/your_template/html/modules.php). Edit the file as follows:

1.       Delete all but the modChrome_xhtml function.

2.       Rename your function to modChrome_xhtmlLinkedTitle (or name of choice).

3.       Add the new parameter to output the URL in the H3 title, <?php echo $params->get('titleLink'); ?>

Your final code should look like one below:

function modChrome_xhtmlLinkedTitle ($module, &$params, &$attribs)

{

if (!empty ($module->content)) : ?>

<div class="TitleLinkedMenu">

<?php if ($module->showtitle != 0) : ?>

<h3><a href="/internet-marketing-blog/get('titleLink'); ?>"><?php echo $module->title; ?></a></h3>

<?php endif; ?>

<?php echo $module->content; ?>

</div>

<?php endif;

}

4.       Save and upload your modified file.

Finally, call the new module in your template index.php file, <jdoc:include type="modules" style="xhtmlLinkedTitle"/>.

Whatever the scenario, I hope the solution above proves useful.

 

Last modified on Monday, 25 October 2010 06:16
Miguel

Miguel

E-mail: This e-mail address is being protected from spambots. You need JavaScript enabled to view it

Add comment



Call Us: +27 11 612 7460