[RISOLTO][PHP] Problema Pagination

Kolop

Utente Attivo
20 Mar 2017
57
0
6
22
Salve, sto usando Cutenews e ho un piccolo problema di Pagination.

Ora è così:



E vorrei che appaia così:



Senza quei ... e tutti quei numeri oltre.

Il codice è questo:

PHP:
// Get config
$_enable_pagination = getoption('disable_pagination') ? FALSE : TRUE;

// Enable ignore rewrite for pagination
$_ignore_rewrite    = isset($ignore_rewrite) && $ignore_rewrite ? true : false;
$ignore_rewrite     = false;

// No pagination, if showed rows less than number
if ($_cn <= $number || !$number)
{
    $_enable_pagination = FALSE;
}

// in case of pagination
if ($_enable_pagination)
{   
    $PSTF = array('category' => '');
    $out = cn_get_template('prev_next', $template);

    // <!--- PREV
    $_prev_num = $start_from - $number;

    // Back to previous page
    if ($_prev_num >= 0)
    {
        if (getoption('rw_engine') && !$_ignore_rewrite)
        {
            if ($tag)
            {
                $url = cn_rewrite('tag', $tag, $_prev_num, $PSTF);
            }
            else
            {
                $url = cn_rewrite('list', $_prev_num, $archive, $PSTF);
            }
        }
        else
        {
            $url = cn_url_modify("start_from=$_prev_num");
        }

        $PREV = '<a class="cn-previous-news" href="'.$url.'">\\1</a>';       
    }
    // Back to first page
    elseif ( $start_from && $_prev_num>0 )
    {
        if (getoption('rw_engine') && !$_ignore_rewrite)
        {
            if ($tag)
            {
                $url = cn_rewrite('tag', $tag, 0, $PSTF);
            }
            else
            {
                $url = cn_rewrite('list', 0, $archive, $PSTF);
            }
        }
        else
        {
            $url = cn_url_modify('start_from');
        }

        $PREV = '<a class="cn-previous-news" href="'.$url.'">\\1</a>';       
    }
    else
    {
        $PREV = '\\1';
    }

    // NEXT --->
    if ($number && ($start_from + $number < $_cn))
    {
        $_next_num = $start_from + $number;

        if (getoption('rw_engine') && !$_ignore_rewrite)
        {
            if ($tag)
            {
                $url = cn_rewrite('tag', $tag, $_next_num, $PSTF);
            }
            else
            {
                $url = cn_rewrite('list', $_next_num, $archive, $PSTF);
            }
        }
        else
        {
            $url = cn_url_modify("start_from=$_next_num");
        }

        $NEXT = '<a class="cn-next-news" href="'.$url.'">\\1</a>';
    }
    else
    {
        $NEXT = '\\1';
    }

    // Settings for Prev and Next
    if ($no_prev)
    {
        $PREV = '';
    }
    if ($no_next)
    {
        $NEXT = '';
    }

    // One is has
    if (!$no_prev || !$no_next)
    {
        $links  = '';
        $out = preg_replace('/\[prev\-link\](.*)\[\/prev\-link\]/is', $PREV, $out);
        $out = preg_replace('/\[next\-link\](.*)\[\/next\-link\]/is', $NEXT, $out);

        // Get page count, if $number is present
        $pages  = $number ? (intval($_cn / $number) + (($_cn % $number == 0) ? 0 : 1)) : 0;       
        // Limits
        $limit_skip   = false;
        $page_limits  = getoption('pagination_pages') ? getoption('pagination_pages') : 2;
        $current_page = intval($start_from / $number);       
        $limit_left   = $current_page - $page_limits;
        $limit_right  = $current_page + $page_limits;

    for ($i = 0; $i < $pages; $i++)
        {
            $_next_num = $number * $i;

            if (getoption('rw_engine') && !$_ignore_rewrite)
            {
                if ($tag)
                {
                    $url = cn_rewrite('tag', $tag, $_next_num, $PSTF);
                }
                else
                {
                    $url = cn_rewrite('list', $_next_num, $archive, $PSTF);
                }
            }
            else
            {
                $url = cn_url_modify("start_from=$_next_num");
            }
            if ($limit_skip == false && ($limit_left >= $i || $i > $limit_right))
            {
                $links .= '<span class="cn-page-skip">...</span> ';
                $limit_skip = true;
            }
            elseif ($i != $current_page) //$start_from != $_next_num
            {               
                $links .= '<a class="cn-page-news" href="'.$url.'">'.($i+1).'</a> ';
                $limit_skip = false;
            }
            else
            {
                $links .= '<span class="cn-current-page-news">'.($i+1).'</span> ';
                $limit_skip = false;
            }
        }
        
        $out = str_replace('{pages}', $links, $out);
        echo $out;
    }
}
Non conosco niente di PHP quindi chiedo a voi. Grazie.
 

Kolop

Utente Attivo
20 Mar 2017
57
0
6
22
Ho risolto modificando questa stringa finale:

PHP:
 if ($limit_skip == false && ($limit_left >= $i || $i > $limit_right))
            {
                $links .= '<span class="cn-page-skip"></span> ';
                $limit_skip = false;
            }
Ditemi se si può fare di meglio oppure va bene così. Il risultato anche così c'è...
 
Ultima modifica: