Connect with Kenyan Premier League (KPL)

Copy below codes and put them where you want the product to be displayed on your website. Some of these codes require some php settings enabled for them to work.

Kenyan Premier League – KPL Table

Table JSON Format

https://www.kenyanpremierleague.com/wp-json/sportspress/v2/tables/5249

PHP Codes

<?php 
//requires PHP cURL library 
//////////Edit from///////// 
$title = "SPL League Table";// Edit Title 
$number = 18; //Edit number of teams to show 
$columns = "home,away,nextmatch,p,w,d,l,f,a,gd,pts,form"; //Edit columns to include all seperated with comma
$showlogo = 0;// either 1 for yes or 0 for no
$link_teams = 1;//either 1 for yes or 0 for no
////////////////Do NOT Edit below here///////////// 
$url = "http://www.kenyanpremierleague.com/table/?title=".urlencode($title)."&number=".$number."&columns=".$columns."&showlogo=".$showlogo."&link=".$link_teams.""; 
//////curl starts here////// 
$ch = curl_init(); 
$timeout = 5; 
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); 
$data = curl_exec($ch); 
curl_close($ch); 
echo $data; 
?>

Table function for WordPress users

If you are using WordPress copy the below codes and paste them in your theme functions file to create a shortcode below. The created shortcode can be used anywhere on the website to display KPL Table.

[kpl_table]

or if you would like to configure the table options, use the following shortcode. This enables you to change title, number of teams to show and columns.

[kpl_table title="SPL League Table" number="18" columns="home,away,nextmatch,p,w,d,l,f,a,gd,pts,form" showlogo="0" link_teams="1"]

Word press shortcode function

//Copy and paste this codes in your theme functions file preferably at the very bottom//
function KPL_table_func($atts){
//requires PHP cURL library
$a = shortcode_atts( array(
'title'=>'SPL League Table',
'number'=>18,
'columns'=>"nextmatch,p,w,d,l,f,a,gd,pts,form", //possible columns home,away,nextmatch,p,w,d,l,f,a,gd,pts,form ///
'showlogo'=>0,
'link_teams'=>1,
), $atts );
//Do NOT Edit below here
$url = "https://www.kenyanpremierleague.com/table/?title=".urlencode($a['title'])."&number=".$a['number']."&columns=".$a['columns']."&showlogo=".$a['showlogo']."&link=".$a['link_teams']."";
//curl starts here
$ch = curl_init();
$timeout = 5;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
add_shortcode( 'kpl_table', 'KPL_table_func' );

Kenyan Premier League Fixtures

To show fixtures and results on your website, use the following php and css codes on your website.

<?php 
//requires PHP cURL library 
//////////Edit from///////// 
$title = "SPL Fixtures";// Edit Title 
$number = 18; //Edit number of teams to show 
$status = "future"; //Either future or publish to show Fixture or Results respectively
$order = "ASC"; //either ASC or DESC
$teamid = "0"; //To show club fixtures only type the team id here. Check the website for club ID. 0 to show all
////////////////Do NOT Edit below here///////////// 
$url = "https://www.kenyanpremierleague.com/kpl-fixtures/?title=".urlencode($title)."&number=".$number."&status=".$status."&order=".$order."&teamid=".$teamid."";
//////curl starts here////// 
$ch = curl_init(); 
$timeout = 5; 
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); 
$data = curl_exec($ch); 
curl_close($ch); 
echo $data; 
?>

Fixtures function for WordPress users

If you are using WordPress copy the below codes and paste them in your theme functions file to create a shortcode below. The created shortcode can be used anywhere on the website to display KPL Fixture and Results.

[kpl_fixtures]

or if you would like to configure the table options, use the following shortcode. This enables you to change title, number of teams to show and columns.

Fixtures

[kpl_fixtures title="SPL Fixtures" number="10" status="future" order="ASC" teamid="0"]

Results

[kpl_fixtures title="SPL Results" number="10" status="publish" order="DESC" teamid="0"]

Team Id’s

Team Name, TeamID
==================
AFC Leopards, 50
Bandari, 40
Chemilil Sugar, 48
Gor Mahia, 46
kakamega Homeboyz, 49
Kariobangi Sharks, 45
Mathare United, 44
Nakumatt, 41
Nzoia Sugar, 39
Posta Rangers, 43
Sofapaka, 51
SoNy Sugar, 47
Thika United, 37
Tusker, 38
Ulinzi Stars, 54
Vihiga United, 3235
Wazito, 3239
Zoo, 42
Mount Kenya United, 4839
KCB, 1940

Word press shortcode function

//Copy and paste this codes in your theme functions file preferably at the very bottom//
function KPL_fixtures_func($atts){
//requires PHP cURL library//
$f = shortcode_atts( array(
'title'=>'SPL Fixtures/Results',
'number'=>18,//number of events to show
'status'=>"future", //Either future or publish to show Fixture or Results respectively//
'order'=>"ASC", //either ASC or DESC//
'teamid'=>"0", //To show club fixtures only type the team id here. Check the website for club ID. 0 to show all//
), $atts );
//Do NOT Edit below here//
$url = "https://www.kenyanpremierleague.com/kpl-fixtures/?title=".urlencode($f['title'])."&number=".$f['number']."&status=".$f['status']."&order=".$f['order']."&teamid=".$f['teamid']."";
//curl starts here//
$ch = curl_init();
$timeout = 5;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
add_shortcode( 'kpl_fixtures', 'KPL_fixtures_func' );

CSS Guide

/*You can edit to meet your website style.*/
.sp-event-blocks thead {
	display: none;
}
.sp-event-blocks .sp-event-date,
.sp-event-blocks .sp-event-time,
.sp-event-blocks .sp-event-results,
.sp-event-blocks .sp-event-title {
	text-align: center;
	display: block;
	margin: 10px 0;
	clear: none;
}
.sp-event-blocks .sp-event-league,
.sp-event-blocks .sp-event-season,
.sp-event-blocks .sp-event-venue {
	text-align: center;
	margin: 0 20%;
	padding: 0 20px;
}
.sp-event-blocks .team-logo {
	margin: 10px;
	width: 20%;
	height: 4em;
	max-width: 6em;
	text-align: center;
}
.sp-event-blocks .logo-odd {
	float: left;
}
.sp-event-blocks .logo-even {
	float: right;
}
.sp-event-blocks .team-logo img {
	max-width: 100%;
	max-height: 100%;
	width: auto;
	height: auto;
}
.sp-fixtures-results {
	clear: both;
}
.widget .sp-event-blocks .sp-event-title {
	margin: 10px;
	padding: 0;
	clear: both;
}
.sp-result{
	background:#00589F;
	color:#fff;
	padding:4px 6px 4px 6px;
	font-size:1em;
}