There might already be a module to do this but I want to learn so i figured that this might be a nice oppertunity. It works on my website, but I must stress the fact that i'm not a programmer so the code might not be efficient or correct.
Here we go. We're going to create a new block so we need to create 2 new files and edit 2 more.
- Edit modules/news/xoops_version.php
find
$modversion['blocks'][4]['file'] = "news_top.php";
$modversion['blocks'][4]['name'] = _MI_NEWS_BNAME5;
$modversion['blocks'][4]['description'] = "Shows recent articles";
$modversion['blocks'][4]['show_func'] = "b_news_top_show";
$modversion['blocks'][4]['edit_func'] = "b_news_top_edit";
$modversion['blocks'][4]['options'] = "published|10|25";
$modversion['blocks'][4]['template'] = 'news_block_new.html';
add after
$modversion['blocks'][5]['file'] = "news_last.php";
$modversion['blocks'][5]['name'] = _MI_NEWS_BNAME6;
$modversion['blocks'][5]['description'] = "Shows last news item";
$modversion['blocks'][5]['show_func'] = "b_news_last_show";
$modversion['blocks'][5]['template'] = 'news_block_last.html';
Now we're going to create news_last.php. Create this file in /modules/news/blocks/, and insert the following code:
function b_news_last_show($options) {
global $xoopsDB;
$myts =& MyTextSanitizer::getInstance();
$block = array();
$result = $xoopsDB->query("SELECT storyid, title, bodytext, hometext FROM ".$xoopsDB->prefix("stories")." WHERE published < ".time()." AND (expired > ".time()." OR expired = 0) ORDER BY published DESC");
list($fsid, $ftitle, $fbodytext, $fhometext) = $xoopsDB->fetchRow($result);
$block['story_title'] = $myts->makeTboxData4Show($ftitle);
$block['story_id'] = $fsid;
$block['story_body'] = $myts->makeTboxData4Show($fbodytext);
$block['story_home'] = $myts->makeTboxData4Show($fhometext);
return $block;
}
?>
next step is the creation of the template for this block. Create a html file called: news_block_last.html . This file must be in modules/news/templates/blocks/
insert the following code
<{if $block.story_id != ""}>
<a href="<{$xoops_url}>/modules/nieuws/article.php?storyid=<{$block.story_id}>"><{$block.story_title}>a><br /><br />
<{$block.story_home}>
<br /><br />
<{$block.story_body}>
<{/if}>
Now there is only one file left to edit. Go to /modules/news/language/{
your language}/modinfo.php and add this at line 16:
define('_MI_NEWS_BNAME6','last news item');
Only thing left to do is to update the news module. Go to admin section/modules and update news. Go to blocks and make the block visible, it should work now.
I hope this helps.