{"id":2095,"date":"2020-12-09T10:58:51","date_gmt":"2020-12-09T07:58:51","guid":{"rendered":"https:\/\/loquiz.com\/support\/?p=2095"},"modified":"2021-06-29T10:52:01","modified_gmt":"2021-06-29T07:52:01","slug":"creating-custom-leaderboard","status":"publish","type":"post","link":"https:\/\/loquiz.com\/support\/creating-custom-leaderboard\/","title":{"rendered":"Creating custom leaderboard"},"content":{"rendered":"\n<p>This tutorial explains how to build a simple leaderboard for your game(s) in your own server and connect it to Loquiz teams database. This can be fully designed by you and hosted at your own server. It is in addition to Loquiz result pages.<\/p>\n\n\n\n<!--more-->\n\n\n\n<h2 class=\"wp-block-heading\">Prerequizites<\/h2>\n\n\n\n<p>You need following things in order to generate your leaderboard outside of  Loquiz. <\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Your accounts API key<\/li><li>Game ID for the game you are building the leaderboard for<\/li><li>Access to a webserver<\/li><\/ul>\n\n\n\n<p>To get the <strong>API key<\/strong> for your Loquiz account, logi into Loquiz Creator, go to User Menu-&gt;Account settings-&gt;API and Generate new API key.  You do not need to generate new API key for every leaderboard, but it might be wise to use different API keys for the leaderboards hosted in different servers.  After generating the API, copy it in full for later use.<\/p>\n\n\n\n<p class=\"has-text-align-center\"><strong>If you can not find the API tab on your Account settings please contact us at hello@loquiz.com in order to activate the feature.<\/strong><\/p>\n\n\n\n<p>Easiest place to find the <strong>Game ID<\/strong> is from the Games Results link URL. To extract the Game ID log into the Loquiz Creator,  find the game you want to create the leaderboard for and click the Results link.  The ID is the code within the URL. Copy that for your later use.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\n\/\/ API configuration\ndefine('LOQUIZ_API_URL', 'https:\/\/api.loquiz.com\/v3\/');\ndefine('LOQUIZ_AUTHORIZATION_HEADER', 'ENTER_YOUR_API_KEY_HERE');\n\nif (substr(LOQUIZ_AUTHORIZATION_HEADER, 0, 9) != 'ApiKey-v1') {\n  die('Please enter your Loquiz API authorization header in this file. Get your authorization header from Loquiz PRO -&gt; Account settings -&gt; API.');\n}\n\n\/\/ Filters\n$gameId = ''; \/\/ game id from Loquiz\n$scope = ''; \/\/ leave empty to get teams from all scopes OR specify one or multiple scopes separated by a comma\n\nif (!$gameId) {\n  die('Please enter a $gameId in this file. Get your game ID by opening a results page on Loquiz PRO and copying the ID from the URL.');\n}\n\n\/\/ Sorting\n$sort = '-totalScore'; \/\/ sort by total score descending\n\n\/\/ Pagination (these values can be used to show results page-by-page)\n$skip = 0; \/\/ start reading paginated list from start\n$limit = 30; \/\/ read up to 30 teams (100 is max in Loquiz API)\n\n\/\/ Function to make Loquiz API GET requests\n\/\/ NB: HTTPS calls require that the curl extension is enabled\nfunction loquiz_get($path) {\n  $ch = curl_init();\n  curl_setopt($ch, CURLOPT_URL, LOQUIZ_API_URL . $path);\n  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);\n  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);\n  curl_setopt($ch, CURLOPT_ENCODING, true);\n  curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: ' . LOQUIZ_AUTHORIZATION_HEADER));\n\n  $response = curl_exec($ch);\n  curl_close($ch);\n\n  return json_decode($response);\n}\n\n\/\/ Load game data\n$game = loquiz_get(\"\/games\/{$gameId}\");\n\n\/\/ Load teams\n$teams = loquiz_get(\"\/results\/{$gameId}\/teams?scope={$scope}&amp;sort={$sort}&amp;skip={$skip}&amp;limit={$limit}\");\n\n\/\/ HTML\n?&gt;&lt;!DOCTYPE html&gt;\n&lt;html&gt;\n  &lt;head&gt;\n    &lt;meta charset=\"utf-8\"&gt;\n    &lt;title&gt;Loquiz results&lt;\/title&gt;\n    &lt;style&gt;\n    .container {\n      max-width: 1200px;\n      margin: auto;\n    }\n\n    table {\n      width: 100%;\n    }\n\n    th {\n      text-align: left;\n    }\n    &lt;\/style&gt;\n  &lt;\/head&gt;\n\n  &lt;body&gt;\n    &lt;div class=\"container\"&gt;\n      &lt;!-- Game info --&gt;\n      &lt;h1&gt;&lt;?php echo $game-&gt;title; ?&gt;&lt;\/h1&gt;\n      &lt;p&gt;&lt;?php echo $teams-&gt;total; ?&gt; team(s) have played&lt;\/p&gt;\n\n      &lt;!-- Results table --&gt;\n      &lt;table&gt;\n        &lt;tr&gt;\n          &lt;th&gt;Rank&lt;\/th&gt;\n          &lt;th&gt;Team&lt;\/th&gt;\n          &lt;th&gt;Score&lt;\/th&gt;\n          &lt;th&gt;Finished?&lt;\/th&gt;\n          &lt;th&gt;Correct answers&lt;\/th&gt;\n          &lt;th&gt;Incorrect answers&lt;\/th&gt;\n          &lt;th&gt;Odometer&lt;\/th&gt;\n        &lt;\/tr&gt;\n        &lt;!-- Every $team has id, scope, name, color, members, startTime, totalScore, correctAnswers, incorrectAnswers, isFinished, hints, odometer --&gt;\n        &lt;?php foreach ($teams-&gt;items as $index =&gt; $team): ?&gt;\n        &lt;tr&gt;\n          &lt;td&gt;&lt;?php echo $index + 1; ?&gt;&lt;\/td&gt;\n          &lt;td style=\"color: &lt;?php echo $team-&gt;color; ?&gt;\"&gt;&lt;?php echo $team-&gt;name; ?&gt;&lt;\/td&gt;\n          &lt;td&gt;&lt;?php echo $team-&gt;totalScore; ?&gt;&lt;\/td&gt;\n          &lt;td&gt;&lt;?php echo $team-&gt;isFinished ? 'finished' : 'not finished'; ?&gt;&lt;\/td&gt;\n          &lt;td&gt;&lt;?php echo $team-&gt;correctAnswers; ?&gt;&lt;\/td&gt;\n          &lt;td&gt;&lt;?php echo $team-&gt;incorrectAnswers; ?&gt;&lt;\/td&gt;\n          &lt;td&gt;&lt;?php echo round($team-&gt;odometer, 2); ?&gt; km&lt;\/td&gt;\n        &lt;\/tr&gt;\n        &lt;?php endforeach; ?&gt;\n      &lt;\/table&gt;\n\n      &lt;!-- Game logo --&gt;\n      &lt;p&gt;\n        &lt;img src=\"&lt;?php echo $game-&gt;logoUrl; ?&gt;\"&gt;\n      &lt;\/p&gt;\n    &lt;\/div&gt;\n  &lt;\/body&gt;\n&lt;\/html&gt;<\/code><\/pre>\n\n\n\n<p> your Loquiz result pages still operate in a normal way.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This tutorial explains how to build a simple leaderboard for your game(s) in your own server and connect it to Loquiz teams database. This can be fully designed by you and hosted at your own server. It is in addition to Loquiz result pages.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[178],"tags":[],"class_list":["post-2095","post","type-post","status-publish","format-standard","hentry","category-integration"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Creating custom leaderboard - Loquiz knowledgebase<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/loquiz.com\/support\/creating-custom-leaderboard\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Creating custom leaderboard - Loquiz knowledgebase\" \/>\n<meta property=\"og:description\" content=\"This tutorial explains how to build a simple leaderboard for your game(s) in your own server and connect it to Loquiz teams database. This can be fully designed by you and hosted at your own server. It is in addition to Loquiz result pages.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/loquiz.com\/support\/creating-custom-leaderboard\/\" \/>\n<meta property=\"og:site_name\" content=\"Loquiz knowledgebase\" \/>\n<meta property=\"article:published_time\" content=\"2020-12-09T07:58:51+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-06-29T07:52:01+00:00\" \/>\n<meta name=\"author\" content=\"Eric\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Eric\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/loquiz.com\\\/support\\\/creating-custom-leaderboard\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/loquiz.com\\\/support\\\/creating-custom-leaderboard\\\/\"},\"author\":{\"name\":\"Eric\",\"@id\":\"https:\\\/\\\/loquiz.com\\\/support\\\/#\\\/schema\\\/person\\\/146baa991dc15587d39906934da45dc7\"},\"headline\":\"Creating custom leaderboard\",\"datePublished\":\"2020-12-09T07:58:51+00:00\",\"dateModified\":\"2021-06-29T07:52:01+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/loquiz.com\\\/support\\\/creating-custom-leaderboard\\\/\"},\"wordCount\":236,\"articleSection\":[\"Integration\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/loquiz.com\\\/support\\\/creating-custom-leaderboard\\\/\",\"url\":\"https:\\\/\\\/loquiz.com\\\/support\\\/creating-custom-leaderboard\\\/\",\"name\":\"Creating custom leaderboard - Loquiz knowledgebase\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/loquiz.com\\\/support\\\/#website\"},\"datePublished\":\"2020-12-09T07:58:51+00:00\",\"dateModified\":\"2021-06-29T07:52:01+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/loquiz.com\\\/support\\\/#\\\/schema\\\/person\\\/146baa991dc15587d39906934da45dc7\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/loquiz.com\\\/support\\\/creating-custom-leaderboard\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/loquiz.com\\\/support\\\/creating-custom-leaderboard\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/loquiz.com\\\/support\\\/creating-custom-leaderboard\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/loquiz.com\\\/support\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Creating custom leaderboard\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/loquiz.com\\\/support\\\/#website\",\"url\":\"https:\\\/\\\/loquiz.com\\\/support\\\/\",\"name\":\"Loquiz knowledgebase\",\"description\":\"Helping you run awesome games\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/loquiz.com\\\/support\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/loquiz.com\\\/support\\\/#\\\/schema\\\/person\\\/146baa991dc15587d39906934da45dc7\",\"name\":\"Eric\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/a1e259c3c8e8b2207b5c23cb8d985fdf416d68c8b2854f582c0a0f89b81b6eba?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/a1e259c3c8e8b2207b5c23cb8d985fdf416d68c8b2854f582c0a0f89b81b6eba?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/a1e259c3c8e8b2207b5c23cb8d985fdf416d68c8b2854f582c0a0f89b81b6eba?s=96&d=mm&r=g\",\"caption\":\"Eric\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Creating custom leaderboard - Loquiz knowledgebase","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/loquiz.com\/support\/creating-custom-leaderboard\/","og_locale":"en_US","og_type":"article","og_title":"Creating custom leaderboard - Loquiz knowledgebase","og_description":"This tutorial explains how to build a simple leaderboard for your game(s) in your own server and connect it to Loquiz teams database. This can be fully designed by you and hosted at your own server. It is in addition to Loquiz result pages.","og_url":"https:\/\/loquiz.com\/support\/creating-custom-leaderboard\/","og_site_name":"Loquiz knowledgebase","article_published_time":"2020-12-09T07:58:51+00:00","article_modified_time":"2021-06-29T07:52:01+00:00","author":"Eric","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Eric","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/loquiz.com\/support\/creating-custom-leaderboard\/#article","isPartOf":{"@id":"https:\/\/loquiz.com\/support\/creating-custom-leaderboard\/"},"author":{"name":"Eric","@id":"https:\/\/loquiz.com\/support\/#\/schema\/person\/146baa991dc15587d39906934da45dc7"},"headline":"Creating custom leaderboard","datePublished":"2020-12-09T07:58:51+00:00","dateModified":"2021-06-29T07:52:01+00:00","mainEntityOfPage":{"@id":"https:\/\/loquiz.com\/support\/creating-custom-leaderboard\/"},"wordCount":236,"articleSection":["Integration"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/loquiz.com\/support\/creating-custom-leaderboard\/","url":"https:\/\/loquiz.com\/support\/creating-custom-leaderboard\/","name":"Creating custom leaderboard - Loquiz knowledgebase","isPartOf":{"@id":"https:\/\/loquiz.com\/support\/#website"},"datePublished":"2020-12-09T07:58:51+00:00","dateModified":"2021-06-29T07:52:01+00:00","author":{"@id":"https:\/\/loquiz.com\/support\/#\/schema\/person\/146baa991dc15587d39906934da45dc7"},"breadcrumb":{"@id":"https:\/\/loquiz.com\/support\/creating-custom-leaderboard\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/loquiz.com\/support\/creating-custom-leaderboard\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/loquiz.com\/support\/creating-custom-leaderboard\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/loquiz.com\/support\/"},{"@type":"ListItem","position":2,"name":"Creating custom leaderboard"}]},{"@type":"WebSite","@id":"https:\/\/loquiz.com\/support\/#website","url":"https:\/\/loquiz.com\/support\/","name":"Loquiz knowledgebase","description":"Helping you run awesome games","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/loquiz.com\/support\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/loquiz.com\/support\/#\/schema\/person\/146baa991dc15587d39906934da45dc7","name":"Eric","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/a1e259c3c8e8b2207b5c23cb8d985fdf416d68c8b2854f582c0a0f89b81b6eba?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/a1e259c3c8e8b2207b5c23cb8d985fdf416d68c8b2854f582c0a0f89b81b6eba?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/a1e259c3c8e8b2207b5c23cb8d985fdf416d68c8b2854f582c0a0f89b81b6eba?s=96&d=mm&r=g","caption":"Eric"}}]}},"_links":{"self":[{"href":"https:\/\/loquiz.com\/support\/wp-json\/wp\/v2\/posts\/2095","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/loquiz.com\/support\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/loquiz.com\/support\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/loquiz.com\/support\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/loquiz.com\/support\/wp-json\/wp\/v2\/comments?post=2095"}],"version-history":[{"count":6,"href":"https:\/\/loquiz.com\/support\/wp-json\/wp\/v2\/posts\/2095\/revisions"}],"predecessor-version":[{"id":8888,"href":"https:\/\/loquiz.com\/support\/wp-json\/wp\/v2\/posts\/2095\/revisions\/8888"}],"wp:attachment":[{"href":"https:\/\/loquiz.com\/support\/wp-json\/wp\/v2\/media?parent=2095"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/loquiz.com\/support\/wp-json\/wp\/v2\/categories?post=2095"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/loquiz.com\/support\/wp-json\/wp\/v2\/tags?post=2095"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}