1
Anonymous
Automatic generation of category-based templates
  • 2004/3/11 23:01

  • Anonymous

  • Posts: 0

  • Since:


Sometimes it would be nice if every category could have it's own different templates. This is a quick and dirty solution. News module is taken as example. Open news/xoops_version.php in an editor and replace this code:

le="color: #000000"><?php // Templates $modversion['templates'][1]['file'] = 'news_archive.html'; $modversion['templates'][1]['description'] = ''; $modversion['templates'][2]['file'] = 'news_article.html'; $modversion['templates'][2]['description'] = ''; $modversion['templates'][3]['file'] = 'news_index.html'; $modversion['templates'][3]['description'] = ''; $modversion['templates'][4]['file'] = 'news_item.html'; $modversion['templates'][4]['description'] = '';


with this code:

le="color: #000000"><?php // Templates $modversion['templates'][1]['file'] = 'news_archive.html'; $modversion['templates'][1]['description'] = ''; $modversion['templates'][2]['file'] = 'news_article.html'; $modversion['templates'][2]['description'] = ''; $modversion['templates'][3]['file'] = 'news_index.html'; $modversion['templates'][3]['description'] = ''; $modversion['templates'][4]['file'] = 'news_item.html'; $modversion['templates'][4]['description'] = ''; $modversion['templates'][5]['file'] = 'news_article1.html'; $modversion['templates'][5]['description'] = 'Kat-ID 1'; global $xoopsDB; $i = 6; $result = $xoopsDB->query("SELECT topic_id FROM ".$xoopsDB->prefix("topics").""); while (list($topic_id) = $xoopsDB->fetchRow($result)) { $modversion['templates'][$i]['file'] = 'news_article'.$topic_id.'.html'; $modversion['templates'][$i]['description'] = 'Kat-ID '.$topic_id; $quelle = XOOPS_ROOT_PATH.'/modules/news/templates/news_article.html'; $ziel = XOOPS_ROOT_PATH.'/modules/news/templates/news_article'.$topic_id.'.html'; if ( !file_exists(XOOPS_ROOT_PATH.'/modules/news/templates/news_article'.$topic_id.'.html') ) { copy($quelle, $ziel); } $i++; }


Open news/article.php in an editor and delete following line:

le="color: #000000"><?php $xoopsOption['template_main'] = 'news_article.html';


Insert following line before including footer.php:

le="color: #000000"><?php $xoopsOption['template_main'] = 'news_article'.$article->topicid().'.html';


This it how it works: First you have to create categories in news, then you have to update the module. Then go to the Templates-Manager and generate the new templates. The original news_article.html is the source for the copies, so if you want to spare some time you can change this FILE.

Unfortunately news/templates must be writable.

I think my solution will work for any module working with categories.

Login

Donat-O-Meter

Stats
Goal: $15.00
Due Date: Jul 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $15.00
Make donations with PayPal!

Latest GitHub Commits