The Joomla! Forum ™



Forum rules


Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.



Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Creating a plugin...
PostPosted: Wed Apr 25, 2012 2:54 pm 
Joomla! Apprentice
Joomla! Apprentice

Joined: Mon Jan 05, 2009 3:39 pm
Posts: 6
I have written some code that basically popup when the user gets to the end of an article and recommends another one to read that is similar in choice.

I have this code basically hacked into my system. I am planning on an upgrade and would like to stick this code into a plugin and make the whole thing modular.

I have followed the tutorials all day trying to get it to work..

Can someone help out here..? I dont think the function inside the plugin is even being called.

Best Regards,
Sounder


Top
 Profile  
 
 Post subject: Re: Creating a plugin...
PostPosted: Wed Apr 25, 2012 9:08 pm 
Joomla! Enthusiast
Joomla! Enthusiast

Joined: Thu Jan 11, 2007 6:00 am
Posts: 205
Location: New Hampshire - United States
First make sure the plugin is published.

I assume this is a plugin of type "content" and that it is for Joomla 2.5. Carefully check the class and function names. If you have this in the XML file:

Code:
<files>
      <filename plugin="my_joomla_plugin">my_joomla_plugin.php</filename>
      ...


In the file my_joomla_plugin.php you must have (with the capital M):

Code:

// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );

class plgContentMy_joomla_plugin extends JPlugin
{

...


The available functions you can put in your class for a content plugin in Joomla 2.5 include the following (note these are different than the function names used for Joomla 1.5):

onContentAfterDelete
onContentAfterDisplay
onContentAfterSave
onContentAfterTitle
onContentBeforeDelete
onContentBeforeDisplay
onContentBeforeSave
onContentChangeState
onContentPrepare
onContentPrepareData
onContentPrepareForm
onContentSearch
onContentSearch
onContentSearchAreas

The most commonly used function for replacing plugin tags in article content is probably onContentPrepare.

Code:

public function onContentPrepare($context, &$row, &$params, $page = 0)
{

   $row->text = str_replace('{some_plugin_tag}', 'some replacement text', $row->text);
   
}


_________________
http://www.madblanks.com - Quiz, survey, assessment, custom calculator, general purpose form extension


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 



Who is online

Users browsing this forum: No registered users and 11 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group