|
Joomla PHP Plugin is a plugin for Joomla that allows you to add custom PHP via a plugin. The Plugin uses the Joomla Content Events, so that you can add to, or modify the Joomla articles before display.
Joomla PHP Plugin Compatibility
The Joomla PHP Plugin is has two version, one for Joomla1.0 and the other for Joomla1.5. Please download the respective version for your Joomla installation.
Download Joomla PHP Plugin
Joomla PHP Installation and Configuration
-
Download the latest version of Joomla PHP Plugin from our Open Source Joomla Plugins Download Section.
-
In your Joomla Administration Panel, go to Installers -> Mambots and upload the Joomla PHP Plugin Installation package you downloaded.
-
Go to the Mambot Administration Panel: Mambots -> Site Mambots, choose the "Joomla PHP Plugin" plugin from the list and choose "Edit" to edit the parameters.
-
Add the PHP you need to the different Content Events in the Plugin Parameters.
-
Publish the Plugin.
Frequently Asked Questions
Does the Joomla PHP Plugin allow me to add PHP code directly to Joomla Content Items?
No, It doesn't. You have to add your PHP code to the Plugin Parameters. This controls the display of the Content Items.
Is there a way to add PHP directly to Content Items?
We will be adding this functionality to Joomla PHP Plugin in the next release.
Documentation and Examples
After installing Joomla PHP Plugin through the Joomla Admin Panel, choose it from the list of installed site mambot so that you can edit its parameters. In the parameters you will find 3 parameters. All three parameters take PHP/HTML/CSS/JavaScript etc.
How to use the "On Preapare" Parameter
The parameter labbelled "On Prepare" takes some PHP code which will modify the $row Object. The $row Object represents the article. The article content is held in the property $row->text.
Example 1: Add a horizontal rule to the end of an article
<?php
$row->text .= '<br />';
?>
This will add a tag to the end of the article content.
Example2: Replace strings in an article content
<?php
global $mosConfig_sitename;
if (isset($row->text)) {
$row->text = str_replace('{sitename}', $mosConfig_sitename, $row->text);
}
?>
This will replace all instances of {sitename} with the value of $mosConfig_sitename in the article contents, where $mosConfig_sitename is the name of your Joomla/Mambo website.
How to use the "Before Content" Parameter
The parameter labbelled "Before Content" takes some PHP code which will display above the article. Use the echo() function instead of return() to display content. Note: This parameter only works if your server supports output buffering. Otherwise it will not show anything.
Example 1: Add google adsense code above all articles
<script type="text/javascript"><!--
google_ad_client = "pub-0553268877774585";
google_ad_width = 468;
google_ad_height = 60;
google_ad_format = "468x60_as";
google_ad_type = "image";
//2007-03-06: fiji web design
google_ad_channel = "9343350244";
google_color_border = "FFFFFF";
google_color_bg = "FFFFFF";
google_color_link = "FF6600";
google_color_text = "000000";
google_color_url = "FF6633";
//--></script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
All you need to do is copy and paste google adsense text into the parameter field. The ad will then show above all content items.
Example2: Add Custom CSS to all articles
<style>
h4 { font-weight: bold; }
p { margin-bottom: 10px; }
</style>
Note that this is just an example. CSS inside the HTML Body is invalid xHTML.
How to use the "After Content" Parameter
The "After Content" Parameter is just like the before content parameter, but it places the php/html/css/javascript etc. at the bottom of the article.
Example1: Show the article's last modified and creation date.
<?php
if (isset($row->created)) {
echo '<p>';
echo '<b>Created on</b>: '.$row->created;
if (isset($row->modified) && $row->modified) {
echo ' <b>Last modified on</b>: '.$row->modified;
}
echo '</p>';
}
?>
|
|