1
Glanz
Need block for NEWS module, that can display full last news article
  • 2004/4/8 11:13

  • Glanz

  • Just popping in

  • Posts: 10

  • Since: 2003/10/27


Subj. Can smbd help me?

2
meme
Re: Need block for NEWS module, that can display full last news article
  • 2004/4/8 12:42

  • meme

  • Quite a regular

  • Posts: 271

  • Since: 2002/12/10


maybe incblocks the best module for that

3
ladon
Re: Need block for NEWS module, that can display full last news article
  • 2004/4/8 12:58

  • ladon

  • Quite a regular

  • Posts: 284

  • Since: 2003/10/31


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.

4
Glanz
Re: Need block for NEWS module, that can display full last news article
  • 2004/4/10 8:56

  • Glanz

  • Just popping in

  • Posts: 10

  • Since: 2003/10/27


Thank you VERY much for you help!

WBR
Pete Glanz

5
Glanz
Re: Need block for NEWS module, that can display full last news article
  • 2004/4/10 8:56

  • Glanz

  • Just popping in

  • Posts: 10

  • Since: 2003/10/27


Thank you VERY much for you help!

WBR
Pete Glanz

6
Mithrandir
Re: Need block for NEWS module, that can display full last news article

I would suggest a little addition to the query:

$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 LIMIT 0,1");

to avoid fetching hundreds of news items when all you need is just one.

7
ladon
Re: Need block for NEWS module, that can display full last news article
  • 2004/4/10 19:16

  • ladon

  • Quite a regular

  • Posts: 284

  • Since: 2003/10/31


@Mithrandir: Yes, thank you, it seems i had forgotten that.

@Glanz: Glad to be of help.

8
banned
Re: Need block for NEWS module, that can display full last news article
  • 2004/9/9 0:58

  • banned

  • Not too shy to talk

  • Posts: 159

  • Since: 2004/5/16


Hi, first of all this is a great one. ;)

How I can show link and bb code in this block?

Login

Who's Online

275 user(s) are online (170 user(s) are browsing Support Forums)


Members: 0


Guests: 275


more...

Donat-O-Meter

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

Latest GitHub Commits