How to create a module with DirectPHP plugin (for Joomla 1.0.x)

Posted: May 19, 2010 in Joomla, PHP
Tags: ,

You can easily create Joomla modules using the DirectPHP plugin.

In this article, I will show you how to create a module similar to the Most Popular module (mod_mostread) that comes with the standard Joomla installation.

Our version of “Most Popular” module has one additional enhancement: it will list the total number of hits for each listing as shown below:

codehunterbd

Here are the steps to create a Joomla module:

1. Go to Module Manager by selecting “Modules – Site Modules” from the top menu.

codehunterbd

2.Click New to create a new module.

3.Give it a title. Let’s name it “Most Popular v2”.
Select a Position. If you’re using the standard installation, you can leave it as ‘Left’.
Also, make sure ‘Yes’ is selected for Published.

codehunterbd

4.Scroll all the way to the bottom. You will see a field called Custom Output as shown below:

codehunterbd

5.Now copy and paste the following code into the content area:

setQuery( $query, 0, $count );
$rows = $database->loadObjectList();

echo '
    '; foreach($rows as $row) { echo "
  • $row->title ($row->hits views)
  • "; } echo ''; ?>

6.If you’ve copied and pasted the code from this web page, most likely you will see the format set to “preformatted”. Highlight all the text and make sure you change it to “Paragraph”:

codehunterbd

7.Now click Save or Apply.

8.For this example, we’re using database query. So you need to allow DirectPHP to execute those commands. Go to “Mambots – Site Mabots”, click on “DirectPHP”, and then on the right hand side where it says Enable PHP Command Block, change it from ‘Yes’ to ‘No’.

codehunterbd

Note: Please make sure you’re only doing this on your development machine. It’s too dangerous to do this on a live machine, unless you’re the only one managing your website.

9.You’re done creating the module! Try loading your Joomla home page. You should be able to see the new module “Most Popular v2” appearing on the left hand side of the page as shown below:

codehunterbd

Of course the above code is extremely simplified. I just want to show you that creating a Joomla module using DirectPHP plugin is simple and straightforward.

If you want, you can refer to mod_mostread.php and put in a more complex database query that checks access control, whether it’s published or not, and adds a link to the article, etc.

Advertisements
Comments
  1. watch movies online says:

    Awesome web site, I hadn’t come across codehunterbd.wordpress.com previously in my searches!
    Carry on the great work!

  2. Hello, if you are interested about sports betting, visit this BetClick bookmaker.

    BetClic has the biggest choice of bets across the big games for soccer, rugby, tennis right through to hockey. On the really big games you can bet live right up to the 90th minute. It’s more fun watching a match when you have bet on

  3. I never comment on blogs, but this one is awesome! Thanks. haircuts

  4. codehunterbd says:

    Thanks too all stay with this blog because it’s update daily. 😀

  5. Hey the whole world! I’m totally new and wanted to just say hello!

  6. “How to create a module with DirectPHP plugin (for Joomla 1.
    0.x) Codehunterbd” was in fact a great
    blog. If solely there were alot more sites similar to this one on the actual internet.
    Anyhow, thanks for your personal precious time, Leola

  7. Katy says:

    I like it whenever people come together and share views, great http://forum.beet.free.fr/profile.php?mode=viewprofile&u=692 – website, keep writing.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s