News module expansion

Talk about new features for CMSMS and modules.
Post Reply
stopsatgreen
Power Poster
Power Poster
Posts: 322
Joined: Sat Feb 04, 2006 1:24 am

News module expansion

Post by stopsatgreen »

I'm sure this is not a new request, but I'd really like to see the news module expanded - especially in regards to an archive feature:

* Next  > Previous to show 10 news items per page, etc, without having to build a ton of pages
* Sort by year

I'm sure there's more, but that's all I can think of now :)
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm

Re: News module expansion

Post by calguy1000 »

these sound like great ideas (pagination of some sort), and expanded sort abilities
wanna put some feature requests into the forge?
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
stopsatgreen
Power Poster
Power Poster
Posts: 322
Joined: Sat Feb 04, 2006 1:24 am

Re: News module expansion

Post by stopsatgreen »

OK, I've made a request in the forge. Fingers crossed we'll see this soon :)
tkcent

Re: News module expansion

Post by tkcent »

Patricia wrote: Actually, the pagination is already something in a feature request in the forge for the core,
for content and content modules. And I think it's even already attributed to a dev ;)
Hopefully they can tie into something generic like the Pager package in PEAR.

http://pear.php.net/package/Pager/

Hear is another package that could be useful:

http://pear.php.net/package/Structures_DataGrid/
rcp

Re: News module expansion

Post by rcp »

Hi!

I whipped up a pagination feature in my News module. The code is a bit ugly but it was the best I could do in 60 minutes :D

action.default.php:

Code: Select all

        $query .= "(".$db->IfNull('start_time',"'".$db->DBTimeStamp(1)."'")." < '".$db->DBTimeStamp(time())."') ";
        $query .= "((".$db->IfNull('end_time',"'".$db->DBTimeStamp(1)."'")." = '".$db->DBTimeStamp(1)."') OR (end_time > '".$db->DBTimeStamp(time())."')) 

        #ADD these lines
        $qq=preg_replace('/SELECT .+ FROM/','SELECT COUNT(*) as total FROM',$query);
        $dbr =& $db->Execute($qq);
        $rr = $dbr->FetchRow();</b>
        $total=$rr['total'];

...

        #SUBSTITUTE old code 
        $dbresult = '';
        $number = -1;
        if( isset( $params['number'] ) )
        {
            $number = $params['number'];
        }

        $inicio=$_GET['inicio']*$number;

        $start = -1;
        if( isset( $params['start'] ) )
        {
            $start = $params['start'];
        }
        if ($_GET['inicio']>0) {
            $start=$_GET['inicio']*$number;
        }

        if( $start >= 0 || $number >= 0 )
        {
            $dbresult =& $db->SelectLimit($query, $number, $start);
        }
        else
        {
            $dbresult =& $db->Execute($query);
        }

        while ($dbresult && $row = $dbresult->FetchRow())
        {

....

            $onerow->author = $theuser->username;
            $onerow->id = $row['news_id'];

            #ADD these lines
            $onerow->start = $start;
            $onerow->number = $number;
            $onerow->total = $total;
            $onerow->inicio = $inicio;
In the summary template: (must have php enabled in config.php)

Code: Select all

{/foreach}

<!-- End News Display Template -->

{php}
#ADD this code snippet
$eu=$_SERVER['REQUEST_URI'];
$sem=preg_replace('/\&inicio=.+$/','',$eu);
if ($start<0) $start=0;

for ($f=0;$f<($total/$number);$f++) {
   if ($start!=$f*$number)
        echo "<a href='$sem&inicio=".$f."'>".($f+1)."</a>   ";
   else
        echo '['.($f+1).']   ';
}
{/php}
I didn't have the need to put a Next/Prev link but as you can see is pretty simple to add them.
I hope this helps anyone :D
kazkas

Re: News module expansion

Post by kazkas »

I just wonder how You made that thing working, 'cause when you put
{php}
    echo "Start: $start; Number: $number; Total: $total;";

before the rest of new code in template, you got
Start: ;
Number: ;
Total: ;
OK, I know a little bit about smarty, so my sollution was:

first 4 rows insert in default.php changed into
$qq = "SELECT COUNT(*) as total " . strstr($query, 'FROM ');
        $dbr =& $db->Execute($qq);
        $rr = $dbr->FetchRow();
        $total=$rr['total'];

and in template I added those rows:

{php}
$number = $this->_tpl_vars['entry']->number;
$total = $this->_tpl_vars['entry']->total;
$start = $this->_tpl_vars['entry']->start;
$eu=$_SERVER['REQUEST_URI'];
$sem=preg_replace('/\&inicio=.+$/','',$eu);
if ($start".($f+1)."   ";
  else
        echo '['.($f+1).']   ';
}
{/php}

now everything seems to be working for me. At least at first sight  ::)
Post Reply

Return to “Feature ideas”