https://github.com/Upstatement/routes
Simple routing for WordPress
https://github.com/Upstatement/routes
Last synced: 3 months ago
JSON representation
Simple routing for WordPress
- Host: GitHub
- URL: https://github.com/Upstatement/routes
- Owner: Upstatement
- Created: 2014-10-30T03:15:53.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2025-02-25T18:08:54.000Z (4 months ago)
- Last Synced: 2025-03-31T21:43:04.010Z (3 months ago)
- Language: PHP
- Homepage:
- Size: 84 KB
- Stars: 189
- Watchers: 29
- Forks: 42
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Routes
Simple routing for WordPress. Designed for usage with [Timber](https://github.com/timber/timber)[](https://travis-ci.org/Upstatement/routes)
[](https://coveralls.io/r/Upstatement/routes?branch=master)
[]()### Basic Usage
```php
/* functions.php */
Routes::map('myfoo/bar', 'my_callback_function');
Routes::map('my-events/:event', function($params) {
$event_slug = $params['event'];
$event = new ECP_Event($event_slug);
$query = new WPQuery(); //if you want to send a custom query to the page's main loop
Routes::load('single.php', array('event' => $event), $query, 200);
});
```Using routes makes it easy for you to implement custom pagination — and anything else you might imagine in your wildest dreams of URLs and parameters. OMG so easy!
## Some examples
In your functions.php file, this can be called anywhere (don't hook it to init or another action or it might be called too late)```php
'foo', 'bar' => 'I dont even know');
Routes::load('archive.php', $params, $query);
});
```## map
`Routes::map($pattern, $callback)`
### Usage
A `functions.php` where I want to display custom paginated content:
```php