I know, I know, this again?
I've pored over the forum and tried the typical suggestions (this and this), but the most recent post I found is 8 years old, and it seems things have changed somewhat since then.
I understand the basic principles, but I'm struggling with the execution. So with that in mind, how can I use {writeTopTenRow} in the main.tpl file? What do I need to add/change in the main.php file to make this happen?
[SOLVED] Adding the Top Ten to main page
Moderator: Thorsten
[SOLVED] Adding the Top Ten to main page
Last edited by openeye on Mon Apr 01, 2013 6:15 pm, edited 1 time in total.
Re: Adding the Top Ten to main page
OK, I finally figured it out on my own. For those wondering, the change I made to main.php (and remember, I'm running version 2.7.9) was to add
to the processTemplate() method. So what you end up with is:
Now hang on, because you're not done yet. That $topten variable is the result of some parsing I also added to the main.php file. The method you need to get the top ten already exists, but it returns an array, thus:
Note that the $topten_arr['id'] is the result of a bit of custom fiddling I did with in the inc/Faq.php file.
If you want to see what $faq->getTopTen() outputs so you can wrap your head around the parsing of it, add
immediately before
to the getTopTen() method in inc/Faq.php.
UPDATE 2013-07-08: I just upgraded to 2.8.1 and had to re-setup all of this. I'm pleased to say that it still works.
Code: Select all
'writeTopTenRow' => $topten,
Code: Select all
$tpl->processTemplate('writeContent', array(
'writeTopTenRow' => $topten,
'writeNewsHeader' => $writeNewsHeader,
'writeNewsRSS' => $writeNewsRSS,
'writeNews' => $news->getNews($archived),
'showAllNews' => $showAllNews,
'writeNumberOfArticles' => $plr->getMsg('plmsgHomeArticlesOnline', $faq->getNumberOfRecords($LANGCODE))));
$tpl->includeTemplate('writeContent', 'index');
Code: Select all
$topten_arr = $faq->getTopTen(); // Get the top ten
$topten = ''; // Instantiate the $topten var
if(array_key_exists('error', $topten_arr)) { // Check to see if zero results were returned
$topten = 'No results!'; // Output in case the were zero results
} else {
for($i=0; $i<count($topten_arr['id']); $i++) { // Loop for as many entries as exist (because it may be fewer than 10)
$topten .= ''; // Build your output HTML
}
}
If you want to see what $faq->getTopTen() outputs so you can wrap your head around the parsing of it, add
Code: Select all
echo '<pre>';
var_dump($output);
echo '</pre>';
die();
Code: Select all
return $output;
UPDATE 2013-07-08: I just upgraded to 2.8.1 and had to re-setup all of this. I'm pleased to say that it still works.