public function parseRequest($url) {
$url = trim($url, '/');
$query = [
'post_type' => null,
'slug' => null,
'taxonomy' => null,
'term' => null,
'paged' => $_GET['page'] ?? 1,
'search' => $_GET['s'] ?? null
];
if ($url === '' || $url === 'home') {
$this->is_front_page = true;
$this->is_home = true;
return $query;
}
$segments = explode('/', $url);
// Taxonomy URL: /movies/action
if (count($segments) == 2) {
$query['post_type'] = $segments[0];
$query['taxonomy'] = 'genre';
$query['term'] = $segments[1];
$this->is_tax = true;
$this->is_archive = true;
return $query;
}
// Single post: /post/slug
if ($segments[0] === 'post' && isset($segments[1])) {
$slug = $segments[1];
// Single query here
$record = (new Query(ctabletalk('posts')))
->setArgs(['slug' => $slug])
->first();
if ($record) {
$this->queried_object = $record;
$query['post_type'] = 'post';
$query['slug'] = $slug;
$this->is_single = true;
$this->is_singular = true;
return $query;
}
}
// Page: /about
$slug = $segments[0];
$record = (new Query(ctabletalk('posts')))
->setArgs(['slug' => $slug])
->first();
if ($record) {
$this->queried_object = $record;
$query['post_type'] = $record['post_type']; // autodetect
$query['slug'] = $slug;
$this->is_page = true;
$this->is_singular = true;
return $query;
}
// 404
$this->is_404 = true;
return $query;
}