{"id":13594186,"url":"https://github.com/Upstatement/routes","last_synced_at":"2025-04-09T07:31:02.614Z","repository":{"id":22610478,"uuid":"25952750","full_name":"Upstatement/routes","owner":"Upstatement","description":"Simple routing for WordPress","archived":false,"fork":false,"pushed_at":"2025-02-25T18:08:54.000Z","size":86,"stargazers_count":189,"open_issues_count":4,"forks_count":42,"subscribers_count":29,"default_branch":"master","last_synced_at":"2025-03-31T21:43:04.010Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Upstatement.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2014-10-30T03:15:53.000Z","updated_at":"2025-03-28T12:26:06.000Z","dependencies_parsed_at":"2025-03-10T18:10:23.396Z","dependency_job_id":"90ce18e8-b724-4079-b5f9-bcf4c25eced9","html_url":"https://github.com/Upstatement/routes","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Upstatement%2Froutes","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Upstatement%2Froutes/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Upstatement%2Froutes/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Upstatement%2Froutes/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Upstatement","download_url":"https://codeload.github.com/Upstatement/routes/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247737758,"owners_count":20987718,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T16:01:29.921Z","updated_at":"2025-04-09T07:31:02.587Z","avatar_url":"https://github.com/Upstatement.png","language":"PHP","readme":"# Routes\nSimple routing for WordPress. Designed for usage with [Timber](https://github.com/timber/timber)\n\n[![Build Status](https://img.shields.io/travis/Upstatement/routes/master.svg?style=flat-square)](https://travis-ci.org/Upstatement/routes)\n[![Coverage Status](https://img.shields.io/coveralls/Upstatement/routes.svg?style=flat-square)](https://coveralls.io/r/Upstatement/routes?branch=master)\n[![Packagist Downloads](https://img.shields.io/packagist/dt/Upstatement/routes.svg?style=flat-square)]()\n\n\n### Basic Usage\n```php\n/* functions.php */\nRoutes::map('myfoo/bar', 'my_callback_function');\nRoutes::map('my-events/:event', function($params) {\n    $event_slug = $params['event'];\n    $event = new ECP_Event($event_slug);\n    $query = new WPQuery(); //if you want to send a custom query to the page's main loop\n    Routes::load('single.php', array('event' =\u003e $event), $query, 200);\n});\n```\n\nUsing 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!\n\n## Some examples\nIn 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)\n\n```php\n\u003c?php\nRoutes::map('blog/:name', function($params){\n    $query = 'posts_per_page=3\u0026post_type='.$params['name'];\n    Routes::load('archive.php', null, $query, 200);\n});\n\nRoutes::map('blog/:name/page/:pg', function($params){\n    $query = 'posts_per_page=3\u0026post_type='.$params['name'].'\u0026paged='.$params['pg'];\n    $params = array('thing' =\u003e 'foo', 'bar' =\u003e 'I dont even know');\n    Routes::load('archive.php', $params, $query);\n});\n```\n\n## map\n\n`Routes::map($pattern, $callback)`\n\n### Usage\n\nA `functions.php` where I want to display custom paginated content:\n\n```php\n\u003c?php\nRoutes::map('info/:name/page/:pg', function($params){\n\t//make a custom query based on incoming path and run it...\n\t$query = 'posts_per_page=3\u0026post_type='.$params['name'].'\u0026paged='.intval($params['pg']);\n\n\t//load up a template which will use that query\n\tRoutes::load('archive.php', null, $query);\n});\n```\n\n### Arguments\n\n`$pattern` (required)\nSet a pattern for Routes to match on, by default everything is handled as a string. Any segment that begins with a `:` is handled as a variable, for example:\n\n**To paginate:**\n\n```\npage/:pagenum\n```\n\n**To edit a user:**\n\n```\nmy-users/:userid/edit\n```\n\n`$callback`\nA function that should fire when the pattern matches the request. Callback takes one argument which is an array of the parameters passed in the URL.\n\nSo in this example: `'info/:name/page/:pg'`, $params would have data for:\n* `$data['name']`\n* `$data['pg']`\n\n... which you can use in the callback function as a part of your query\n\n* * *\n\n## load\n\n`Routes::load($php_file, $args, $query = null, $status_code = 200)`\n\n### Arguments\n\n`$php_file` (required)\nA PHP file to load, in my experience this is usually your archive.php or a generic listing page (but don't worry it can be anything!)\n\n`$template_params`\nAny data you want to send to the resulting view. Example:\n\n```php\n\u003c?php\n/* functions.php */\n\nRoutes::map('info/:name/page/:pg', function($params){\n    //make a custom query based on incoming path and run it...\n    $query = 'posts_per_page=3\u0026post_type='.$params['name'].'\u0026paged='.intval($params['pg']);\n\n    //load up a template which will use that query\n    $params['my_title'] = 'This is my custom title';\n    Routes::load('archive.php', $params, $query, 200);\n});\n```\n\n```php\n\u003c?php\n/* archive.php */\n\nglobal $params;\n$context['wp_title'] = $params['my_title']; // \"This is my custom title\"\n/* the rest as normal... */\nTimber::render('archive.twig', $context);\n```\n\n`$query`\nThe query you want to use, it can accept a string or array just like `Timber::get_posts` -- use the standard WP_Query syntax (or a WP_Query object too)\n\n`$status_code`\nSend an optional status code. Defaults to 200 for 'Success/OK'\n","funding_links":[],"categories":["PHP"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FUpstatement%2Froutes","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FUpstatement%2Froutes","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FUpstatement%2Froutes/lists"}