|
Joomla PHP Pages Component allows you to create simple PHP pages and link them to the Joomla Menu. This allows you to easily create a custom page without having to create a whole component. It is similar to the PHP Module for Joomla, except that it is a full Component.
Joomla PHP Component Compatibility
The Joomla PHP Component is compatible with Joomla1.0 and Joomla1.5. You need to download the correct version for your Joomla version as there is no backward compatibility between versions.
Download Joomla PHP Component
Joomla PHP Component Installation
-
Download the latest version of Joomla PHP Component from our Joomla PHP Extensions Download.
-
In your Joomla Administration Panel, go to Installers -> Components and upload the Joomla PHP Component Installation package you downloaded.
Creating a custom PHP page
Frequently Asked Questions
Do I have to wrap the PHP code in special tags?
No, you can use the regular PHP tags directly. eg: <?php phpinfo(); ?> will display the PHP information.
Can I use predefined Joomla variables?
Yes, but you first have to declare them as globals. eg: global $mainframe;
Can I include PHP files?
Yes, but make sure you use the full path to the PHP files. It's just easier.
Example:
global $mainframe;
include($mainrame->getCfg('absolute_path').'/modules/mod_php/includes/my_php_file.php');
Can I use PHP Component with PHP Module?
Yes, you can even make them work together if you wanted.
Documentation and Examples:
Here are some examples of PHP code you can use in the Joomla PHP Component.
Example Snippet: Show a welcome Message to users:
<?php
/**
* Custom code for mod_php.
* copyright: www.fijiwebdesign.com
* Shows a welcome to the logged in user, or vistor.
*/
global $my;
if ($my->id) {
echo 'Hello, '.$my->username;
} else {
echo 'Hello, visitor';
}
?>
Example Snippet: Display Flickr Photos
<?php
/**
* Example of display flickr photos for a tags list
* Requires: allow_url_fopen enabled in php.ini
*/
/**
* Configurations
*/
// the tags to get photos for
$tags = 'fiji';
// number of pics to show
$total = 5;
// main template
$main_template = '
<!-- photos for: '.$tags.' -->
<div class="flickr_photos">
{photo_template}
</div>
';
// the html template for each photo item/row
$photo_template = '
<div class="flickr_photo">
<img src="{img_src}" width="{img_width}" height="{img_height}" alt="{img_alt}" />
<h4>
<a href="{url}" target="_blank">{title}</a>
</h4>
</div>
';
// css for our photos styling
$css = '
<style type="text/css">
.flickr_photo {
background: #cfcfcf;
text-align: center;
}
.flickr_photo img {
border: 1px solid #000;
}
.flickr_photo h3 {
font-size: 100%;
font-weight: bold;
margin: 0px;
padding: 5px;
}
</style>
';
/**
* End Configurations
* Start Flickr Feed Request and display
*/
$flickr_feed_url = 'http://api.flickr.com/services/feeds/photos_public.gne?tags='.rawurlencode($tags).'&format=php';
include($flickr_feed_url);
$photos_html = '';
if (isset($feed['items']) && ($count = count($feed['items']))) {
$n = $count < $total ? $count : $total;
for($i = 0; $i < $n; $i++) {
$item = $feed['items'][$i];
$row_html = $photo_template;
$repl = $item;
// flickr image is in description, so we have to parse it out
preg_match("/<img src=\"(.*?)\" width=\"(.*?)\" height=\"(.*?)\" alt=\"(.*?)\" (.*?)\/>/ui", $item['description'], $matches);
if ($matches) {
$repl['img_html'] = $matches[0];
$repl['img_src'] = $matches[1];
$repl['img_width'] = $matches[2];
$repl['img_height'] = $matches[3];
$repl['img_alt'] = $matches[4];
}
foreach($repl as $name=>$value) {
$row_html = str_replace('{'.$name.'}', $value, $row_html);
}
$photos_html .= $row_html;
}
} else {
echo 'No photos found for, '.htmlentities($tags);
}
$html = str_replace('{photo_template}', $photos_html, $main_template);
// display
echo $css;
echo $html;
// debug
function dump($obj) {
echo nl2br(str_replace(' ', ' ', htmlentities(print_r($obj, true))));
}
?>
|