Brain-WP / Cortex

Routing system for WordPress
MIT License
347 stars 20 forks source link

Extra exmaples #5

Closed grappler closed 9 years ago

grappler commented 9 years ago

Do you have any simple examples for changing the permalink structure for cpts?

I would like to get this structure but I am not sure it is possible? example.com/{cat}/{post_name}

Thank you.

gmazzap commented 9 years ago

Hi @grappler

in Cortex, there is no permalink structure: there is a completely new way to handle urls: in Cortex you connect a kind of url to a query.

If you want that an url like example.com/{cat}/{post_name} display your post, of course you can have it. You need to set 2 variable parts in the url and assign them to a query.

Something like:

Brain\Routes::add( '/{cat}/{name}' )
  ->requirements([
        // next line ensure that {cat} is a valid category slug
        'cat' => implode('|', wp_list_pluck(get_categories(), 'slug')),
      ])
  ->query( function( $matches ) {
        return ['name' => $matches['name']];
      });