Automatic Blog - Multiple PHP function declaration? - php

I want to generate HTML using PHP based on files in a specific Folder, everything works for the first File but if I add a second File, I just see:
Fatal error: Cannot redeclare getTitle() (previously declared in [path]:3) in [path].php on line 4
I understood the Problem but I don't know how to solve it. This is the PHP-Code of the main File:
foreach (glob("content/blog/*.php") as $file) {
require_once $file;
$index = str_replace("content/blog/", "", str_replace(".php", "", str_replace("img/", "", $file)));
?>
<div class="content">
<h3><?php getTitle() ?><span><?php getPublishedDate() ?></span></h3>
<p><?php getContent() ?></p>
</div>
<?php
$file = null;
}
?>
And this is the PHP-Code in every Blog-File:
<?php
function getTitle() {
echo "Lorem Ipsum 2!";
}
function getPublishedDate() {
echo "When Time has finally come";
}
function getContent() {
echo "<p>Text</p>";
}
?>
I searched for opposites of include, include_once, require or require_once. I also tried Setting the variable back to null before foreach is called again.
Thanks for any help in advance.

Define a class to store the information about one blog post.
// name this file class.blogEntry.php
class blogEntry {
var $title;
var $publishedDate;
var $content;
public function getTitle() {
return $this->title;
}
public function setTitle($title) {
$this->title = $title;
}
public function getPublishedDate() {
return $this->publishedDate;
}
public function setPublishedDate($date) {
$this->publishedDate = $date;
}
public function getContent() {
return $this->content;
}
public function setContent($content) {
$this->content = $content;
}
}
For each blog post create a simple php file to set it's different properties
$entry->setTitle("Lorem Ipsum 2!");
$entry->setPublishedDate("When Time has finally come");
$entry->setContent("<p>Text</p>");
Modify your output to use the class and the class based blog entries
require_once 'class.blogEntry.php';
foreach (glob("content/blog/*.php") as $file) {
$entry = new blogEntry();
require_once $file;
$index = str_replace("content/blog/", "", str_replace(".php", "", str_replace("img/", "", $file)));
?>
<div class="content">
<h3><?php $entry->getTitle() ?><span><?php $entry->getPublishedDate() ?></span></h3>
<p><?php $entry->getContent() ?></p>
</div>
<?php
$file = null;
}
?>

The problem is you have several files, defining the same function getTitle and you are requiring them.
Requiring or including a *.php file is like merging all the code into one single file, which explains the error, because you are requiring n files and in each of them you are defining the same functions.
You can do something like this instead of functions you can use associative array.
<?php
// blog_file_1.php
$prop = array(
'title' => "This is file 1!",
'published_date' => "When Time has finally come",
'content' => "<p>Text</p>"
);
<?php
// blog_file_2.php
$prop = array(
'title' => "This is file 2!",
'published_date' => "When Time has finally come",
'content' => "<p>Text</p>"
);
<?php
// blog.php
foreach (glob("content/blog/*.php") as $file) {
require_once $file;
$index = str_replace("content/blog/", "", str_replace(".php", "", str_replace("img/", "", $file)));
?>
<div class="content">
<h3><?php echo $prop['title'] ?><span><?php echo $prop['published_date'] ?></span></h3>
<p><?php echo $prop['content'] ?></p>
</div>
<?php
$file = null;
}
?>

I'm not sure if this will help you but maybe it will help others that might find this question as it hits what I was looking for. I was looking to exactly this a few days ago and didn't find much for a simple PHP script to generate a blog. I put this together after searching Stack for different functions (Generate gallery with links from a folder, PHP Pagination, Passing Variable from Another PHP File, Sort Files) and put this together.
Code for the main blog page
\\Blog.php
<?php
$directory = "blog/folder/";
$blogfiles = glob($directory . "*.php");
usort($blogfiles, function($file_1, $file_2)
{
$file_1 = filectime($file_1);
$file_2 = filectime($file_2);
if($file_1 == $file_2)
{
return 0;
}
return $file_2 < $file_1 ? 1 : -1;
});
$post_count = 5;
$total_pages = ceil(count($blogfiles)/$post_count);
$page = $_REQUEST['page']; ///make it dyanamic :: page num
$offset = ($page-1)*$post_count;
$files_filter = array_slice($blogfiles, $offset,$post_count);
foreach ($files_filter as $blogfile) {
ob_start();
include "$blogfile";
ob_end_clean();
echo '<div class="blog-post"><a href="'.$blogfile.'"><img src="'.$BLOG_IMG.'"><h1
class="blog-title">' . $BLOG_TITLE . '</h1></a><br><p class="blog-summary">' .
$SUMMARY . '</p></div><hr>', "\n";
}
if($total_pages > 1){
if($page > 1){
echo '<div class="blog-pagination prev-page"><a href="blog.php?page='.($page-
1).'">Prev Page</a></div>';
}
if($page != $total_pages){
echo '<div class="blog-pagination next-page"><a href="blog.php?page='.
($page+1).'">Next Page</a><div class="blog-pagination">';
}
}
?>
Here is a blog post template
\\post1.php
<?php
$DOC_TITLE = "Document Title for browser tab";
$BLOG_TITLE = "Blog Post Title";
$SUMMARY = "Page summary";
$BLOG_IMG = "/Path/to/blog/image.jpg";
require $_SERVER['DOCUMENT_ROOT'] . '/header.php'; //Pre-made HTML header in the root folder - or just replace with HTML header
?>
\\content
<?php
require $_SERVER['DOCUMENT_ROOT'] . '/footer.php'; //Pre-made HTML footer in the root folder - or just replace with HTML footer
?>

Related

Php Code showing Following error in the webpage

am using joomla .. ,
by runnig the joomla it showing the following error in the link part
and the main error is about the parameter is expecting to a reference.
if i change it , it will not show any links
Warning: Parameter 2 to modChrome_artblock() expected to be a
reference, value given in
D:\xampp\htdocs\Site\templates\a_2\html\modules.php on
line 36
Warning: Parameter 3 to modChrome_artblock() expected to be a
reference, value given in
D:\xampp\htdocs\site\templates\a_2\html\modules.php on
line 36
and the php code on this error is
- <?php
defined('_JEXEC') or die;
if (!defined('_ARTX_FUNCTIONS'))
require_once dirname(__FILE__) . str_replace('/', DIRECTORY_SEPARATOR, '/../functions.php');
function modChrome_artstyle($module, &$params, &$attribs)
{
$style = isset($attribs['artstyle']) ? $attribs['artstyle'] : 'art-nostyle';
$styles = array(
'art-nostyle' => 'modChrome_artnostyle',
'art-block' => 'modChrome_artblock',
'art-article' => 'modChrome_artarticle',
'art-vmenu' => 'modChrome_artvmenu'
);
// moduleclass_sfx support:
// '' or 'suffix' - the default module style: custom suffix will not be added to the module tag
// but will be added to the module elements.
// ' suffix' - adds suffix to the module as well as to the module elements.
// 'art-...' - overwrites the default module style.
// 'suffix art-...' - overwrites the default style and adds suffix to the module and
// to its elements, does not add art-... to the module elements.
$classes = explode(' ', rtrim($params->get('moduleclass_sfx')));
$keys = array_keys($styles);
$art = array();
foreach ($classes as $key => $class) {
if (in_array($class, $keys)) {
$art[] = $class;
$classes[$key] = ' ';
}
}
$classes = str_replace(' ', ' ', rtrim(implode(' ', $classes)));
$style = count($art) ? array_pop($art) : $style;
$params->set('moduleclass_sfx', $classes);
> call_user_func($styles[$style], $module, $params, $attribs);
}
function modChrome_artnostyle($module, &$params, &$attribs)
{
if (!empty ($module->content)) : ?>
<!-- begin nostyle -->
<div class="art-nostyle<?php echo $params->get('moduleclass_sfx'); ?>">
<?php if ($module->showtitle != 0) : ?>
<h3><?php echo $module->title; ?></h3>
<?php endif; ?>
<!-- begin nostyle content -->
<?php echo $module->content; ?>
<!-- end nostyle content -->
</div>
<!-- end nostyle -->
<?php endif;
}
function modChrome_artblock($module, &$params, &$attribs)
{
if (!empty ($module->content))
echo artxBlock(($module->showtitle != 0) ? $module->title : '', $module->content,
$params->get('moduleclass_sfx'));
}
function modChrome_artvmenu($module, &$params, &$attribs)
{
if (!empty ($module->content)) {
if (function_exists('artxVMenuBlock'))
echo artxVMenuBlock(($module->showtitle != 0) ? $module->title : '', $module->content,
$params->get('moduleclass_sfx'));
else
echo artxBlock(($module->showtitle != 0) ? $module->title : '', $module->content,
$params->get('moduleclass_sfx'));
}
}
function modChrome_artarticle($module, &$params, &$attribs)
{
if (!empty ($module->content)) {
$data = array('classes' => $params->get('moduleclass_sfx'), 'content' => $module->content);
if ($module->showtitle != 0)
$data['header-text'] = $module->title;
echo artxPost($data);
}
}
it showing the error
call_user_func($styles[$style], $module, $params, $attribs);
try the following, it will solve your problem
Go to Module -> Advance -> Module Style -> Change "inherited" to corresponding position styles. (e.g: select art-nostyle, art-block et)
in that case you don't have to scale down Php version
*****it should open in joomla administrator, then do the above steps
You can use
function modChrome_artblock($module, $params, $attribs)
instead of
function modChrome_artblock($module, &$params, &$attribs)

How to create php file using php

I'm trying to create multiple .php files using php itself.
I want to put some code into a file; most of code is the same but only one or two variables that I wanted to be dynamic. I mean every file that I make are exactly like each other the only difference between theme is one variable.
My function is this:
function generate_corn_files()
{
$C = $GLOBALS['C'];
$db = $GLOBALS['db'];
//delete all contents of folder
RemoveDir($C->INCPATH.'cron/feed/', false);
$res = $db->query('SELECT id FROM category ');
while($cat = $db->fetch_object($res)) {
$id = $cat->id;
$open_output = <<<'PHP'
<?php
$outter_id = $id;
if($example = true){
echo 'test';
echo $C->INCPATH;
}
?>
PHP;
$fp=fopen($C->INCPATH.'cron/feed/filename_'.$id.'.php','w');
fwrite($fp, $open_output);
fclose($fp);
}
}
I tried to put content of file using heredoc but I want to $id in $outter_id = $id; be equal to $id = $cat->id;
it's a variable outside of heredoc I can't make it work inside of it !
Are there any other solutions to make it work ?
You aren't using HEREDOC syntax but rather NOWDOC syntax. If you use HEREDOC, all variables inside will be evaluated, so you will have to escape with \$ the variables you don't want evaluated.
$open_output = <<<PHP
<?php
\$outter_id = $id;
if(\$example = true){
echo 'test';
echo \$C->INCPATH;
}
?>
PHP;
Or, you can stick with NOWDOC, use a placeholder, and replace it afterwards.
$open_output = <<<'PHP'
<?php
$outter_id = %%%id%%%;
if($example = true){
echo 'test';
echo $C->INCPATH;
}
?>
PHP;
str_replace("%%%id%%%", $id, $open_output);
Maybe this could inspire you
function generate_corn_files()
{
$C = $GLOBALS['C'];
$db = $GLOBALS['db'];
//delete all contents of folder
RemoveDir($C->INCPATH.'cron/feed/', false);
$res = $db->query('SELECT id FROM category ');
while($cat = $db->fetch_object($res)) {
$id = $cat->id;
$open_output = <<<'PHP'
<?php
$outter_id = $id;
if($example = true){
echo 'test';
echo $C->INCPATH;
}
?>
PHP;
$php_var_name_pattern = '/\$([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)/';
$open_output = preg_replace_callback(
$php_var_name_pattern,
function($matches) {
if(isset($GLOBALS[$matches[1]])) {
if(is_string($GLOBALS[$matches[1]])) {
return '\''.$GLOBALS[$matches[1]].'\'';
} else {
return $GLOBALS[$matches[1]];
}
} else {
return $matches[0];
}
},
$open_output);
$fp=fopen($C->INCPATH.'cron/feed/filename_'.$id.'.php','w');
fwrite($fp, $open_output);
fclose($fp);
}
}

last.fm api - random / shuffle foreach loop

I am currently working with the lat.fm api to develop an app.
I have a function which runs to pull in the weekly track listing from a last.fm group.
The aim is to pull in the album artwork and to make a "gridview" template.
The below code does this:
public function getWeeklyTrackChartGrid($methodVars) {
// Check for required variables
if ( !empty($methodVars['group']) ) {
$vars = array(
'method' => 'group.getweeklytrackchart',
'api_key' => $this->auth->apiKey
);
$vars = array_merge($vars, $methodVars);
if ( $call = $this->apiGetCall($vars) ) {
$i = 0;
//shuffle($call->weeklytrackchart->track);
$loopN = $call->weeklytrackchart->track;
foreach ($loopN as $track ) {
require 'config.php';
//if(++$i > $userLimit*2) break;
$albumArtS = $tracks['album']['image']['small'] = (string) $track->image[0];
$albumArtM = $tracks['album']['image']['small'] = (string) $track->image[1];
$albumArtL = $tracks['album']['image']['small'] = (string) $track->image[2];
$playCounts = $tracks[$i]['playcount'] = (string) $track->playcount;
?>
<?php if ($playCounts > 1) { ?>
<?php if ($albumArtL) { ?>
<img src="<?php echo $albumArtL; ?>" />
<?php } ?>
<?php } else { ?>
<?php if ($albumArtM) { ?>
<img src="<?php echo $albumArtM; ?>" />
<?php } ?>
<?php } ?>
<?php if ($albumArtwork == "yes") { ?>
<?php if ($albumArt) { ?>
<?php } }?>
<?php $i++;
}
return $tracks;
}
else {
return FALSE;
}
}
else {
// Give a 91 error if incorrect variables are used
$this->handleError(91, 'You must include a group variable in the call for this method');
return FALSE;
}
}
I would like to use the php function shuffle on the foreach loop to randomise the tracks, rather than pull them in, in the order last.fm gives them you.
As you can see i havent commented the shuffle function out above, as when i add this i get the following warning:
Warning: shuffle() expects parameter 1 to be array, object given in
Any ideas on what could be the problem?
Cheers,
Dan
$loopN = (array) $call->weeklytrackchart->track;
shuffle($loopN);

Global Variable Changes to Function's Return Value

On my website i have a PHP file which generates it's menus from an external PHP file (to make updating easier)
heres part of the PHP which outlines the problem:
$products = array("Kinetic","Key","Twister","Ellipse","Focus","Trix","Classic","Pod","Halo","Alu","Rotator","Canvas","Image","Flip","Executive","Torpedo","Nature","Wafer Card","Alloy Card","Bottle Opener","Ink Pen","Clip","Light","Tie Clip","Event Lanyard","Lizzard Wristband","Slap Wristband");
$others = array("Other 1","Other 2","Other 3","Other 4","Other 5");
function genMenu($product) {
global $products;
global $others;
$menu="<div class='titlebar'><div class='title'>USBs</div></div><div class='buttons'>";
for ($x=0;$x<count($products); $x++) {
$p=$products[$x];
$link=strtolower(str_replace(' ', '', $p)).".php";
if($product==$p) {$menu=$menu."<span class='activebutton'><span class='textspace'>» ".$p."</span></span>";}
else {$menu=$menu."<a href='".$link."'><span class='button'><span class='textspace'>» ".$p."</span></span></a>";}
if(count($products)>$x+1) {
$menu=$menu."<img src='layout/seperator.jpg' class='seperator' alt='' width='184' height='2' />";
}
}
$menu=$menu."</div><div class='titlebar'><div class='title'>Other Products</div></div><div class='buttons'>";
for ($y=0;$y<count($others); $y++) {
$o=$others[$y];
$link=strtolower(str_replace(' ', '', $o)).".php";
if($product==$o) {$menu=$menu."<span class='activebutton'><span class='textspace'>» ".$o."</span></span>";}
else {$menu=$menu."<a href='".$link."'><span class='button'><span class='textspace'>» ".$o."</span></span></a>";}
if(count($others)>$y+1) {
$menu=$menu."<img src='layout/seperator.jpg' class='seperator' alt='' width='184' height='2' />";
}
}
$menu=$menu."</div>";
return (string)$menu;
}
function genDrop($product) {
global $products;
global $others;
$drop=$products[12];
return $drop;
}
So, the menu generates using an array of products i have outside the function, enabling their use by making them global... The problem im having is that when the function returns $menu, it also changes $products value to the same. (but not $others)
therefore the second function (genDrop) returns 't' from $menu="<div class='t
is this meant to happen? how do i stop it?
PHP in the HTML that calls the functions:
<?php include("menufoot.php");
$product="Twister";
$products = genMenu($product);
$dropmenu = genDrop($product);
print $dropmenu;
$footer = genFoot($product);
$mobilefooter = genMobFoot($product);
?>

Adding Pagination to a 3rd party module (OT-MiniNewsModule)

i'm currently trying to modify a module that works almost perfectly for my requirements, but lacks pagination. I can't seem to grasp how i should add the pagination to it; most JPagination examples assume i have access to the query but in this module (which uses JFactory, JmoduleHelper & JModel) i don't see the query in order to add the limits and such.
mod_otmininews.php
//No direct access!
defined('_JEXEC') or die;
// Include the syndicate functions only once
require_once dirname(__FILE__).DS.'helper.php';
$doc = &JFactory::getDocument();
$doc->addStyleSheet(JURI::base().'/modules/mod_otmininews/css/layout.css');
$list = modOtMiniNewsHelper::getList($params);
$moduleclass_sfx = htmlspecialchars($params->get('moduleclass_sfx'));
require JModuleHelper::getLayoutPath('mod_otmininews', $params->get('layout', 'default'));
helper.php
//No direct access!
defined('_JEXEC') or die;
require_once JPATH_SITE.'/components/com_content/helpers/route.php';
jimport('joomla.application.component.model');
JModel::addIncludePath(JPATH_SITE.'/components/com_content/models');
abstract class modOtMiniNewsHelper
{
public static function getList(&$params)
{
// Get the dbo
$db = JFactory::getDbo();
// Get an instance of the generic articles model
$model = JModel::getInstance('Articles', 'ContentModel', array('ignore_request' => true));
// Set application parameters in model
$app = JFactory::getApplication();
$appParams = $app->getParams();
$model->setState('params', $appParams);
// Set the filters based on the module params
$model->setState('list.start', 0);
$model->setState('list.limit', (int) $params->get('count', 3));
$model->setState('filter.published', 1);
// Access filter
$access = !JComponentHelper::getParams('com_content')->get('show_noauth');
$authorised = JAccess::getAuthorisedViewLevels(JFactory::getUser()->get('id'));
$model->setState('filter.access', $access);
// Category filter
$model->setState('filter.category_id', $params->get('catid', array()));
// User filter
$userId = JFactory::getUser()->get('id');
switch ($params->get('user_id'))
{
case 'by_me':
$model->setState('filter.author_id', (int) $userId);
break;
case 'not_me':
$model->setState('filter.author_id', $userId);
$model->setState('filter.author_id.include', false);
break;
case '0':
break;
default:
$model->setState('filter.author_id', (int) $params->get('user_id'));
break;
}
// Filter by language
$model->setState('filter.language',$app->getLanguageFilter());
// Featured switch
switch ($params->get('show_featured'))
{
case '1':
$model->setState('filter.featured', 'only');
break;
case '0':
$model->setState('filter.featured', 'hide');
break;
default:
$model->setState('filter.featured', 'show');
break;
}
// Set ordering
$order_map = array(
'm_dsc' => 'a.modified DESC, a.created',
'mc_dsc' => 'CASE WHEN (a.modified = '.$db->quote($db->getNullDate()).') THEN a.created ELSE a.modified END',
'c_dsc' => 'a.created',
'p_dsc' => 'a.publish_up',
'h_dsc' => 'a.hits',
);
$ordering = JArrayHelper::getValue($order_map, $params->get('ordering'), 'a.publish_up');
$dir = 'DESC';
$model->setState('list.ordering', $ordering);
$model->setState('list.direction', $dir);
$items = $model->getItems();
foreach ($items as &$item) {
$item->slug = $item->id.':'.$item->alias;
$item->catslug = $item->catid.':'.$item->category_alias;
if ($access || in_array($item->access, $authorised))
{
// We know that user has the privilege to view the article
$item->link = JRoute::_(ContentHelperRoute::getArticleRoute($item->slug, $item->catslug));
}
else {
$item->link = JRoute::_('index.php?option=com_user&view=login');
}
//$item->title = htmlspecialchars( $item->title );
$item->content= strip_tags(preg_replace('/<img([^>]+)>/i',"",$item->introtext));
$item->content = substr($item->content, 0, $params->get('introtext_limit'));
preg_match_all('/img.+src="([^"]+)"/i', $item->introtext, $matches);
if(empty($matches[1][0])){
$item->images="";
}else{
$item->images= $matches [1] [0];
}
//Show thumbnails
if($params->get('showthumbnails')==1){
if($item->images == ""){
$item->thumbnail = '<img src="'.$params->get('directory_thumbdefault').'" width="'.$params->get('thumbwidth').'" height="'.$params->get('thumbheight').'" alt="'.$item->title.'" />';
}else{
$item->thumbnail = '<img src="' .$item->images.'" width="'.$params->get('thumbwidth').'" height="'.$params->get('thumbheight').'" alt="'.$item->title.'" />' ; //show images
}
}
$item->created_date = $item->created;
}
return $items;
}
}
All this code creates an array used by
default.php
defined('_JEXEC') or die;
?>
<div class="ot_news">
<div class="ot_news_i">
<?php
$count = 0;
foreach ($list as $item) : ?>
<?php $count++; ?>
<div class="ot_items <?php echo ($params->get('count') == $count)?'last-item':''; ?>">
<!-- Show thumbnails -->
<?php if($params->get('showthumbnails') == 1){?>
<div class="ot_thumbs" style="width:<?php echo $params->get('thumbwidth')?>px; height:<?php echo $params->get('thumbheight')?>px;">
<?php if($params->get('enablelinkthumb') == 1) {?>
<?php echo $item->thumbnail ;?>
<?php } else { ?>
<?php echo $item->thumbnail?>
<?php }?>
</div>
<?php } else { ?>
<?php echo ''; ?>
<?php } ?>
<!-- End -->
<!-- Show Titles -->
<div class="ot_articles">
<?php if($params->get('showtitle') == 1) { ?>
<div class="ot_title">
<?php if($params->get('enablelinktitle') == 1) { ?>
<?php echo $item->title; ?>
<?php }else{?>
<span class="title"><?php echo $item->title; ?></span>
<?php }?>
</div>
<?php } ?>
<!-- Show Created Date -->
<?php
if ($params->get('show_date') == 1) {
echo '<p class="createddate"><span class="ot_date">';
$date = $item->created_date;
echo JHTML::_('date', $date, $params->get( 'date_format' ));
echo '</span></p>';
}
?>
<!-- Show Content -->
<div class="ot_content"><?php echo $item->content; ?></div>
<!-- Show Readmore -->
<?php if($params->get('readmore') == 1) {?>
<div class="ot_readmore"><?php echo JText::_('READMORE') ?></div>
<?php }else {?>
<?php echo ''; ?>
<?php } ?>
</div>
</div>
<div class="spaces"></div>
<?php endforeach; ?>
</div>
</div>
<div class="ot-mini-news"><?php echo JText::_('ABOUT_OT_MINI_NEWS'); ?></div>
that just uses a for each to show the items with their photos links and descriptions.
So as you can see i have seriously no clue where to add the Pagination code, and i suspect they even use some part of it for the display (i saw a getlist function in the helper.php file.
Any help would be much appreciated.
http://docs.joomla.org/Using_JPagination_in_your_component This is a highly useful document for this - even though this is for a module and the wiki page is using it for a component.
$db =& JFactory::getDBO();
$lim = $mainframe->getUserStateFromRequest("$option.limit", 'limit', 14, 'int'); //I guess getUserStateFromRequest is for session or different reasons
$lim0 = JRequest::getVar('limitstart', 0, '', 'int');
$db->setQuery('SELECT SQL_CALC_FOUND_ROWS x, y, z FROM jos_content WHERE x',$lim0, $lim);
$rL=&$db->loadAssocList();
if (empty($rL)) {$jAp->enqueueMessage($db->getErrorMsg(),'error'); return;}
else {
////Here the beauty starts
$db->setQuery('SELECT FOUND_ROWS();'); //no reloading the query! Just asking for total without limit
jimport('joomla.html.pagination');
$pageNav = new JPagination( $db->loadResult(), $lim0, $lim );
foreach($rL as $r) {
//your display code here
}
echo $pageNav->getListFooter( ); //Displays a nice footer
You can see in their code that whilst they do use the db result, that the pagination doesn't 'depend' on the query. Only the results which come from it. So for the $db->loadResult() for example you can just use a php count forumla to see how many rows there are in the array being produced by the module. In your case counting the number of $items.
The foreach command is still as you have it as well. With just the foreach($rL as $r) just corresponding to the existing foreach($items as $item). So the fact you don't have the database query as you see - shouldn't actually be an issue!
So the code you want will be something like:
global $option; //If Joomla 1.5
global $mainframe; //If Joomla 2.5
$option = JRequest::getCmd('option') //If Joomla 2.5
$mainframe = JFactory::getApplication(); //If Joomla 2.5
$lim = $mainframe->getUserStateFromRequest("$option.limit", 'limit', 14, 'int'); //I guess getUserStateFromRequest is for session or different reasons
$lim0 = JRequest::getVar('limitstart', 0, '', 'int');
if (empty($items)) {
$app->enqueueMessage($db->getErrorMsg(),'error');
return;
} else {
jimport('joomla.html.pagination');
$pageNav = new JPagination( count($list), $lim0, $lim );
foreach($list as $item) {
//wrap in your code here that you had in the foreach already
}
echo $pageNav->getListFooter( ); //Displays a nice footer
Make sure you remove one of the top two lines depending on whether you're using Joomla 1.5 or 2.5 but that should work.

Categories