All Projects → makeitworkpress → wp-router

makeitworkpress / wp-router

Licence: GPL-3.0 license
Enables developers to easily create custom routes with matching templates accordingly.

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to wp-router

wp-optimize
The WP Optimize class provides a wrapper to optimize WordPress and remove unnecessary or unwanted functions and scripts.
Stars: ✭ 37 (+68.18%)
Mutual labels:  wordpress-development, wordpress-php-library, wordpress-library
wp-better-settings
A simplified OOP implementation of the WP Settings API
Stars: ✭ 14 (-36.36%)
Mutual labels:  wordpress-development, wordpress-php-library
koselig
💌 Seamlessly integrate Wordpress with Laravel.
Stars: ✭ 65 (+195.45%)
Mutual labels:  wordpress-development, wordpress-library
gin
Foundation of the Tonik WordPress Starter Theme. Provides all custom functionalities which it offers.
Stars: ✭ 29 (+31.82%)
Mutual labels:  wordpress-development, wordpress-php-library
wp-admin-notices
A simplified OOP implementation of the WordPress admin notices.
Stars: ✭ 16 (-27.27%)
Mutual labels:  wordpress-development, wordpress-php-library
just-responsive-images
WordPress Plugin to support better responsive images with <picture> tag, backgrounds, retina support etc.
Stars: ✭ 47 (+113.64%)
Mutual labels:  wordpress-development
WordPress-Distribution
This repository helps you to get a local new and fresh WordPress for everything you want (e.g. Developing, Testing, etc.).
Stars: ✭ 16 (-27.27%)
Mutual labels:  wordpress-development
wp-weixin
WordPress WeChat integration
Stars: ✭ 62 (+181.82%)
Mutual labels:  wordpress-development
underpin
A WordPress Framework that makes building scale-able plugins and themes easier.
Stars: ✭ 84 (+281.82%)
Mutual labels:  wordpress-library
humescores
IMPORTANT: Download the Exercise Files from the course page to get the Gulp process files and other important data.
Stars: ✭ 58 (+163.64%)
Mutual labels:  wordpress-development
wp-project-skeleton
A skeleton WordPress project to be used as a base for new WordPress projects.
Stars: ✭ 33 (+50%)
Mutual labels:  wordpress-development
blade
🏃 A library for using Laravel Blade templates in WordPlate.
Stars: ✭ 28 (+27.27%)
Mutual labels:  wordpress-php-library
enveigle
Deceive Ansible to template Trellis .env files to local Bedrock
Stars: ✭ 18 (-18.18%)
Mutual labels:  wordpress-development
view-admin-as
View the WordPress admin as a different role, switch between users, temporarily change your capabilities, set default screen settings for roles, manage your roles and capabilities.
Stars: ✭ 44 (+100%)
Mutual labels:  wordpress-development
wp-modular-css
Plugin to generate a custom Tachyons build from a JSON configuration.
Stars: ✭ 15 (-31.82%)
Mutual labels:  wordpress-development
knob-mvc
[abandoned] Knob is a PHP MVC Framework to create Wordpress templates easier and funnier than ever before.
Stars: ✭ 14 (-36.36%)
Mutual labels:  wordpress-php-library
login-designer
Official repository of the Login Designer WordPress Plugin
Stars: ✭ 97 (+340.91%)
Mutual labels:  wordpress-development
coblocks-theme
WordPress theme for CoBlocks
Stars: ✭ 24 (+9.09%)
Mutual labels:  wordpress-development
cherry-framework
100% GNU GPL WordPress framework
Stars: ✭ 102 (+363.64%)
Mutual labels:  wordpress-development
barebones
React based WordPress Theme, built with create-react-wptheme. This is a starter theme with just the core WordPress functionality.
Stars: ✭ 35 (+59.09%)
Mutual labels:  wordpress-development

wp-router

Enables developers to add custom routes and templates to their WordPress theme. In other Words, you can easily add custom permalinks to your theme such as yourwebsite.dev/custom/ which in order point to a custom template.

WP Router is maintained by Make it WorkPress.

Usage

Include the WP-Router in your plugin, theme or child theme files. Require it in your functions.php file or use a PHP autoloader. You can read more about autoloading in the readme of wp-autoload.

Syntax

new MakeitWorkPress\WP_Router\Router(Array $routes, String $folder, String $query_var, Boolean $debug);

Create a new instance of WP_Router\Router

Create a new instance of the Router class with the array of routes as an argument in the format displayed below.

$router = new MakeitWorkPress\WP_Router\Router( 
    [
        'custom'    => ['route' => custom/, 'title' => __('Custom Template Title')],
        'another'   => ['route' => friedpizza/, 'title' => __('Fried Pizza!')]
    ], 
    'templates',    // The folder in your theme or child theme where the custom templates are stored. Use any full path to locate templates in plugins.
    'template',     // The query var by which the template is identified, in this case through get_query_var('template'). Defaults to template.
    false           // Whether to debug or not, which will output all rewrite rules on the front-end
);
  • The keys of the routes array self indicate the names of the specific template and will also refer to the name of the specific file in your templates folder. Thus, the key custom in the above example will look for the custom.php template file within the templates folder.
  • The route key in the values of this array indicate the Regular Expression for the permalink, while the title key indicates an optional title that is displayed in the head section of your website.
  • Optionally, you can define a custom folder for your templates as a second argument and the custom variable by which a template is queried in the third argument. By default, the templates folder in your theme or child theme is expected.
  • In addition, you can set debug to true to output all current rewrite rules on the front-end

Include template

Include the specific templates in your theme. In the case above, you need to have have a custom.php and an another.php template in the folder /templates/ in your parent or child theme. Obviously, this will be another folder if you changed the second argument.

Flush Permalinks

After adding new routes, do not forget to flush your permalinks. The easiest way to do is to head over to your permalink settings and save your settings. Please note that WP-Router only supports pretty permalinks.

Result

With the above example, you will have yourwebsite.dev/custom/ using templates/custom.php and yourwebsite.dev/friedpizza/ using templates/another.php

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].