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

Canonical links

Discussion in 'XenForo Development Discussions' started by Robust, Dec 6, 2015.

  1. Robust

    Robust Well-Known Member

    So, say I have


    I want to make this:

    I think XenForo calls this canonical requests. How exactly is this feature used? I looked at the thread and forum controllers and tried to see how it works there, but it didn't explain much.

    As always, any help is appreciated :)
  2. Jake B.

    Jake B. Well-Known Member

    It's handled in the route in the buildLink method. If you use XenForo_Link::buildBasicLinkWithIntegerParam you'd just set whatever the title field is (In most default XF things such as conversations and threads it is 'title') as the 6th parameter. Here's what XenForo uses for conversations, and is the most basic example:

        public function buildLink($originalPrefix$outputPrefix$action$extension$data, array &$extraParams)
    $action XenForo_Link::getPageNumberAsAction($action$extraParams);
    Robust likes this.
  3. Jeremy

    Jeremy Well-Known Member

    If you are talking about how XenForo canonicalizes links such as this:




    (or utilizing the proper title) when loading the links, you want to look at and utilize the following functions in your controller action:
    XenForo_Controller::canonicalizeRequestUrl($linkUrl) (takes the response from XenForo_Link::buildPublicLink()) and
    XenForo_Controller::canonicalizePageNumber($page, $perPage, $total, $linkType, $linkData = null)

    Example from the threads controller:
            $this->canonicalizePageNumber($page$postsPerPage$thread['reply_count'] + 1'threads'$thread);
    XenForo_Link::buildPublicLink('threads'$thread, array('page' => $page))
    Robust likes this.
  4. Robust

    Robust Well-Known Member

Share This Page