It has two functions. The first function gets the URL and breaks it into parts. The second function includes the required file based on the URL parts.

public function urlParts()
$this->uri = $_SERVER['REQUEST_URI'];
$this->path = parse_url($this->uri, PHP_URL_PATH);

$temp_path = trim($this->path, '/');
$this->uri_parts = explode('/', $temp_path);

The variable $this->uri_parts[0] contains the first part of URI. This is category of article. The variable $this->uri_parts[1] is the second part of URI, which can be either article or sub category. The third part, $this->uri_parts[2], is the article.

public function route()
// Home Page Layout
if ($this->uri_parts[0] == "")
$this->include = "/layout/home.php";

// Category Layout
else if (isset($this->uri_parts[0]))
$this->include = "/layout/category.php";

If the first part of URI (category) is set, then category page is included, else home page is included.

Category Page

The first part of URL is always the category. It can be:

  1. Parent category containing sub categories
  2. Main category containing articles

How To Find Type of Category

Find categories in the category table, which have parent ID equal to the category ID. If the category contains sub categories, then it is parent category, otherwise it is main category.

What To Display

At this stage, there can be four possibilities based on two deciding factors: type of category and second part of URI.

  1. If second part of URI is not set
    • Category page with list of sub categories
    • Category page with list of articles
  2. If second part of URI is set
    • Include article page if main category
    • Include category page if parent category