1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Paginated Thread: Control Number Of Pages Displayed At Once

Discussion in 'Troubleshooting and Problems' started by TheBigK, Jan 17, 2013.

  1. TheBigK

    TheBigK Well-Known Member

    On a thread spanning several pages, how do I control the number of pages displayed in the list?

    A picture is worth 1000 words: -


    By default, 5 pages are shown at a time. I want to display just 3. So it should display

    [33] [34] [35] , instead of [31] [32] [33] [34] [35] [36].
  2. Chris D

    Chris D XenForo Developer Staff Member

    It might be a template edit. I will look later.

    ... I have to ask, though, why?
  3. MattW

    MattW Well-Known Member

    I think it's controlled by this function in /library/XenForo/Template/Helper/Core.php

            * Helper to get page navigation (all pages, for scrolling pagenav version).
            * @param string $templateClass Name of the template class to instantiate
            * @param string $linkFunction Name of the linking function to call (in this class)
            * @param integer $perPage Items to display per page
            * @param integer $totalItems Total number of items
            * @param integer $currentPage Current page number
            * @param string $linkType Type of link to create
            * @param mixed $linkData Data for the link
            * @param array $linkParams List of key value params for the link; page will be set as needed
            * @param array $options Options to control the building
            * @return string|XenForo_Template_Abstract
    protected static function _getPageNav($templateClass$linkFunction$perPage$totalItems$currentPage,
    $linkType$linkData null, array $linkParams = array(), array $options = array()
    // abort if there are insufficient items to make multiple pages
    if ($totalItems || $perPage 1)
    $options array_merge(
    'unreadLink' => '',
    'template' => 'page_nav',
    'displayRange' => //TODO: make this come from an option?
    $unreadLinkHtml htmlspecialchars($options['unreadLink'], ENT_COMPAT'iso-8859-1'false);
    $pageTotal ceil($totalItems $perPage);
    // abort if there is only one page
    if ($pageTotal <= 1)
                            if (!empty(
                                    return new 
    $templateClass($options['template'], array(
    'unreadLinkHtml' => $unreadLinkHtml,
    'pageTotal' => $pageTotal
    $currentPage min(max($currentPage1), $pageTotal);
    // number of pages either side of the current page
    $range $options['displayRange'];
    $scrollSize $range;
    $scrollThreshold $scrollSize 2;
                    if (
    $pageTotal >$scrollThreshold)
    $startPage max(2$currentPage $range);
    $endPage min($pageTotal$startPage $scrollSize);
    $extraPages $scrollSize - ($endPage $startPage);
                            if (
    $extraPages 0)
    $startPage -= $extraPages;
    $startPage 2;
    $endPage $pageTotal;
                    if (
    $endPage $startPage)
    $pages range($startPage$endPage);
    $pages = array();
                    if (isset(
    $linkParams['_params']) && is_array($linkParams['_params']))
    $tempParams $linkParams['_params'];
    $linkParams array_merge($tempParams$linkParams);
    $templateVariables = array(
    'pageTotal' => intval($pageTotal),
    'currentPage' => $currentPage,
    'pages' => $pages,
    'range' => $range,
    'scrollThreshold' => $scrollThreshold,
    'startPage' => $startPage,
    'endPage' => $endPage,
    'prevPage' => ($currentPage ? ($currentPage 1) : false),
    'nextPage' => ($currentPage $pageTotal ? ($currentPage 1) : false),
    'pageNumberSentinel' => XenForo_Application::$integerSentinel,
    'linkType' => $linkType,
    'linkData' => $linkData,
    'linkParams' => $linkParams,
    'maxDigits' => strlen($pageTotal),
    'unreadLinkHtml' => $unreadLinkHtml
    $template = new $templateClass($options['template'], $templateVariables);
  4. 1BJK903

    1BJK903 Active Member

    Maybe because it looks better if it's less on mobile?
  5. Chris D

    Chris D XenForo Developer Staff Member

    I'm not sure that was the reason at the time. A year ago XenForo didn't have responsive design so it would have looked no better or worse on mobile.
  6. 1BJK903

    1BJK903 Active Member

    Hmm, might be, but personally, I find it better if it were 3 instead of 5. Can you tell me btw how I can make that happen? I am looking at the code, but I can't see where it outputs 5 instead of another number?
  7. Chris D

    Chris D XenForo Developer Staff Member

    In that code. Change:
    $range $options['displayRange'];

    $range 1;
    That will then leave you with a gap like this:


    To close that gap, you need to add this to EXTRA.css:

    .PageNav .scrollable
        width: 70px;
    Note, on a custom style you may need to adjust the width accordingly as it depends on the width and margin of the other elements.

    The end result should be:



Share This Page