1
banned
XoopsPageNav->renderNav($offset, $anchor)
  • 2005/12/6 1:20

  • banned

  • Not too shy to talk

  • Posts: 159

  • Since: 2004/5/16


Hi, there
Today I was in need to pass an html anchor (#something) to XoopsPageNav, the easiest way was to pass it after the url generation, as the #anchors need to be at the end of an url string.
So, I've changed a little the renderNav function (only an $anchor added 4 times), maybe it can be usefull for someone or something - and maybe we can have a pagenav class that pass #anchors in future versions.
here the code..
function renderNav($offset = 4, [color=FF0000]$anchor[/color])
    {
        
$ret = '';
        if ( 
$this->total <= $this->perpage ) {
            return 
$ret;
        }
        
$total_pages = ceil($this->total / $this->perpage);
        if ( 
$total_pages > 1 ) {
            
$prev = $this->current - $this->perpage;
            if ( 
$prev >= 0 ) {
                
$ret .= '<a href="'.$this->url.$prev.[color=FF0000]$anchor.[/color]'">«</a> ';
            }
            
$counter = 1;
            
$current_page = intval(floor(($this->current + $this->perpage) / $this->perpage));
            while ( 
$counter <= $total_pages ) {
                if ( 
$counter == $current_page ) {
                    
$ret .= '<b>('.$counter.')</b> ';
                } elseif ( (
$counter > $current_page-$offset && $counter < $current_page + $offset ) || $counter == 1 || $counter == $total_pages ) {
                    if ( 
$counter == $total_pages && $current_page < $total_pages - $offset ) {
                        
$ret .= '... ';
                    }
                    
$ret .= '<a href="'.$this->url.(($counter - 1) * $this->perpage).[color=FF0000]$anchor.[/color]'">'.$counter.'</a> ';
                    if ( 
$counter == 1 && $current_page > 1 + $offset ) {
                        
$ret .= '... ';
                    }
                }
                
$counter++;
            }
            
$next = $this->current + $this->perpage;
            if ( 
$this->total > $next ) {
                
$ret .= '<a href="'.$this->url.$next.[color=FF0000]$anchor.[/color]'">»</a> ';
            }
        }
        return 
$ret;
    }

Note: the value passed is a complete html anchor, it mean that you need to pass '#anchor' instead of simply 'anchor'.
Maybe someone will need a modified version of this -> I'm looking at XXbit charset users..

banned,