1
limecity
Displaying News by their Category?
  • 2004/5/13 2:25

  • limecity

  • Friend of XOOPS

  • Posts: 1602

  • Since: 2003/7/6 0


Okay..
i seen too much of these already..
How do you do that?

Displaying the news in blocks by category..
How and how?
template tricks?

2
kahumbu
Re: Displaying News by their Category?
  • 2004/5/13 6:11

  • kahumbu

  • Documentation Writer

  • Posts: 277

  • Since: 2003/8/23


I use the Topics Block Module.

3
ladon
Re: Displaying News by their Category?
  • 2004/5/13 14:21

  • ladon

  • Quite a regular

  • Posts: 284

  • Since: 2003/10/31


News 1.2 beta has a block to diplay news per topic. I've send Mithrandir some code to put the option in the old blocks so 1 or more topics can be selected for each block. It uses a multi-select form. Little problem I couldn't figure out how to solve is: it gives each topic the name ARRAY. But that figures, I'm not a coder . It works anyway.

If you don't mind hacking you news module a little, here is the code: (place this in modules/news/news_top.php, replace all.)
function b_news_top_show($options) {
    global 
$xoopsDB;
    
$myts =& MyTextSanitizer::getInstance();
    
$block = array();
    
$options_new array_slice $options); 
    
$topicpick '('.implode ','$options_new ).')'
    if ( 
$options[3] == ) {
        
$sql "SELECT storyid, title, published, expired, counter FROM ".$xoopsDB->prefix("stories")." WHERE published < ".time()." AND published > 0 AND (expired = 0 OR expired > ".time().") ORDER BY ".$options[0]." DESC";
        }
        else {
            
$sql "SELECT storyid, title, published, expired, counter FROM ".$xoopsDB->prefix("stories")." WHERE published < ".time()." AND published > 0 AND (expired = 0 OR expired > ".time().") AND topicid in ".$topicpick." ORDER BY ".$options[0]." DESC";
            }    
$result $xoopsDB->query($sql,$options[1],0);
    while ( 
$myrow $xoopsDB->fetchArray($result) ) {
        
$news = array();
        
$title $myts->makeTboxData4Show($myrow["title"]);
        if ( !
XOOPS_USE_MULTIBYTES ) {
            if (
strlen($myrow['title']) >= $options[2]) {
                
$title $myts->makeTboxData4Show(substr($myrow['title'],0,($options[2] -1)))."...";
            }
        }
        
$news['title'] = $title;
        
$news['id'] = $myrow['storyid'];
        if ( 
$options[0] == "published" ) {
            
$news['date'] = formatTimestamp($myrow['published'],"s");
        } elseif ( 
$options[0] == "counter" ) {
            
$news['hits'] = $myrow['counter'];
        }
        
$block['stories'][] = $news;
    }
    return 
$block;
}

function 
b_news_top_edit($options) {
    global 
$xoopsDB;
    
$form ""._MB_NEWS_ORDER.";
    
$form .= ";
    if ( 
$options[0] == "published" ) {
        
$form .= " selected='selected'";
    }
    
$form .= ">"._MB_NEWS_DATE."n";
    
$form .= ";
    if(
$options[0] == "counter"){
        
$form .= " selected='selected'";
    }
    
$form .= ">"._MB_NEWS_HITS."n";
    
$form .= "n";
    
$form .= " "._MB_NEWS_DISP..$options[1]."' /> "._MB_NEWS_ARTCLS."";
    
$form .= 
"
._MB_NEWS_CHARS..$options[2]."' /> "._MB_NEWS_LENGTH."";
    
$form .= "test";
    include_once 
XOOPS_ROOT_PATH."/class/xoopsstory.php";
    
$xt = new XoopsTopic($xoopsDB->prefix("topics"));
    
$alltopics $xt->getTopicsList();
    
$alltopics[0] = "All topics";
    
ksort($alltopics);
    
$size count($options);
    foreach (
$alltopics as $topicid => $topic) {
        
$sel "";
        for ( 
$i 2$i $size$i++ ) {
            if (
$options[$i] == $topicid) {
                
$sel " selected='selected'";
            }
        }
        
$form .= "$topicid'$sel>$topic";
    }
    
$form .= "";
    return 
$form;
}


If you want to be certain everything works flawless, wait for the release of the new news module or use the Topics Block Module. But as far as I know you can only select 1 topic with that module. If that's enough, no need to use this code

4
limecity
Re: Displaying News by their Category?
  • 2004/5/13 14:29

  • limecity

  • Friend of XOOPS

  • Posts: 1602

  • Since: 2003/7/6 0


hey thanks..
i will give it a try~

5
kahumbu
Re: Displaying News by their Category?
  • 2004/5/13 14:47

  • kahumbu

  • Documentation Writer

  • Posts: 277

  • Since: 2003/8/23


Quote:

But as far as I know you can only select 1 topic with that module.

This is not true. I set 2-3 Topics per block using the Topics Block module. Just separate the News Topic IDs with commas (1,4,8) when you configure a block.

I too am waiting for the new News mod so this will be integrated.

6
Mithrandir
Re: Displaying News by their Category?

To avoid the "array" instead of topic title, replace the last lines with this:
include_once XOOPS_ROOT_PATH."/class/xoopsstory.php";
    
$xt = new XoopsTopic($xoopsDB->prefix("topics"));
    
$alltopics $xt->getTopicsList();
    
$alltopics[0]['title'] = "All topics";
    
ksort($alltopics);
    
$size count($options);
    foreach (
$alltopics as $topicid => $topic) {
        
$sel "";
        for ( 
$i 2$i $size$i++ ) {
            if (
$options[$i] == $topicid) {
                
$sel " selected='selected'";
            }
        }
        
$form .= "$topicid'$sel>".$topic['title']."";
    }
    
$form .= "";

i.e. with these two lines changed:
//$alltopics[0] = "All topics";
//change to
$alltopics[0]['title'] = "All topics";

//$form .= "$topic";
//change to
$form .= "$topicid'$sel>".$topic['title']."";

7
ladon
Re: Displaying News by their Category?
  • 2004/5/13 16:23

  • ladon

  • Quite a regular

  • Posts: 284

  • Since: 2003/10/31


@Mithrandir: Ah, thats nice, now it works as should!

@kahumbu: Oh yes, you're right, guess I confused that one with a different module I once used. I actually had a hack on my news doing it the same way before I made the multi-select.

8
Mithrandir
Re: Displaying News by their Category?

One thing, though - as I am just testing this myself - I haven't been able to get the "All topics" working, so I may just leave that one out.

9
ladon
Re: Displaying News by their Category?
  • 2004/5/13 16:34

  • ladon

  • Quite a regular

  • Posts: 284

  • Since: 2003/10/31


Hmm, that's strange it worked perfectly for me. But I used the news 1.0 version. I'll take a look at it right now, see what's going on (with and without your modifications for the array problem).

And if there really is a problem with it, well, it's not a multi-select for nothing, we can just select all topics

[edit]In my set up (without your changes) it works perfectly. But my girlfriend just got home, gonna see Troy now! I'll look at it later today[/edit]

10
ladon
Re: Displaying News by their Category?
  • 2004/5/13 21:32

  • ladon

  • Quite a regular

  • Posts: 284

  • Since: 2003/10/31


Ok, I've tested it with and without the modifications to solve the "ARRAY" problem. All topics can be displayed by selecting "all topics", it works perfectly. I'm guessing it must have something to do with other modifications made you made in news 1.2

ps. a little typo in the code you gave:
//$form .= "$topic";//change to$form .= "".$topic['title']."";


should be
//$form .= "$topic";//change to$form .= "".$topic['title']."";

(optionvalue => option value)

Login

Who's Online

298 user(s) are online (245 user(s) are browsing Support Forums)


Members: 0


Guests: 298


more...

Donat-O-Meter

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

Latest GitHub Commits