PHP code example of marspress / front-end-route

1. Go to this page and download the library: Download marspress/front-end-route library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

marspress / front-end-route example snippets


$routeSet = new \MarsPress\FrontEndRoute\Route_Set(
    'test_route',
    'route/set',
    'test-route-page',
);

$routeSet->add_routes(
    new \MarsPress\FrontEndRoute\Route( 'this-is-a-route', 'This is a route' ),
    new \MarsPress\FrontEndRoute\Route( 'this-is-another-route', 'This is another route' ),
);

$routeSet = new \MarsPress\FrontEndRoute\Route_Set(
    'test_route',
    'route/set',
    'test-route-page',
);


get_header();

if( $route = $routeSet->is_route() ){

    echo '<h1>This is a query var template</h1>';
    echo "<h2>The route is {$route}</h2>";

    $templatePart = get_stylesheet_directory() . "/template-parts/{$routeSet->get_query_variable()}/{$route}.php";
    if( file_exists( $templatePart ) ){