Page 1 of 1

News module expansion

Posted: Thu Feb 16, 2006 12:02 am
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 :)

Re: News module expansion

Posted: Fri Feb 17, 2006 4:15 am
by calguy1000
these sound like great ideas (pagination of some sort), and expanded sort abilities
wanna put some feature requests into the forge?

Re: News module expansion

Posted: Fri Feb 17, 2006 10:04 am
by stopsatgreen
OK, I've made a request in the forge. Fingers crossed we'll see this soon :)

Re: News module expansion

Posted: Fri Feb 17, 2006 2:57 pm
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/

Re: News module expansion

Posted: Fri Sep 15, 2006 12:01 pm
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

Re: News module expansion

Posted: Mon Apr 16, 2007 1:21 pm
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  ::)