Creating Extensions

From ALSwiki
Jump to: navigation, search

Overview

I wanted to embed selected weblinks in articles. After some searching, I decided the best course of action would be to write my own plugin.

Professional Joomla! (Programmer to Programmer) by Dan Rahmel includes severral chapters on writing plugins. I also had the source code for EasyTube written by Paul Bain (http://www.paulbain.co.uk/simple-youtube-plugin-for-mambo-easytube-mambot/) and for Display News written by Boris Komraz (http://joomlacode.org/gf/project/display_news/).

Download EmbedLinks

Here's the result. To embed links in a page, download and install EmbedLinks. It's here: http://downloads.alstevens.org/

Using EmbedLinks

At the point in an article where you you want the links to appear, add

 {embedlinks CATID=catid}

Replace catid with the category id of the links you want. If CATID is omitted, all published links will be shown:

 {embedlinks}

The admin interface includes parameters for sorting, ordering and limiting the links to be shown. In addition, parameters can be included directly in the embed tag. The syntax is:

 {embedlinks CATID=<catid>|SORTBY=<oneof: title,ordering,hits,date,id>|SORTORDER=<oneof: AZ,ZA>|MAXLINKS=<positive integer>|STARTAT=<positive integer>|SHOWHITS=<one of: yes,no>]

Parameters set in the tag itself override the values set using the admin interface. Parameters can occur in any order. If no links are found, nothing will be shown -- there is no warning or error message. There is no checking for duplicate arguments. The last one set will be the one used.

The result, is inserted into the article as html, For example:

 <ul class="embedLinkList">
   <li class="embedLink"><a href="/index.php?view=weblink&catid=2&id=1&option=com_weblinks">Joomla!</a>Home of Joomla! <span class="embedLinkHits">Viewed 5 times.</span></li>
   <li class="embedLink"><a href="/index.php?view=weblink&catid=2&id=5&option=com_weblinks">Joomla! - Forums</a>Joomla! Forums <span class="embedLinkHits">Viewed 5 times.</span></li>
 </ul>

Any embedLink clicked on will get its click-count incremented.

Styling can be done with these selectors:

 ul.embedLinkList { }
 li.embedLink { }
 li.embedLink a { }
 li.embedLink span.embedLinkHits {}