Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add is_route function #4

Open
vwasteels opened this issue Jun 4, 2013 · 8 comments
Open

add is_route function #4

vwasteels opened this issue Jun 4, 2013 · 8 comments
Assignees

Comments

@vwasteels
Copy link

Hello,

Is there a way to test what route I'm showing,

example, in my header.php, I'd like to do :

if(is_route('my_custom_routing')) { echo 'menu-active'; }

thanks

@jbrinley
Copy link
Owner

jbrinley commented Aug 8, 2013

$router = WP_Router::get_instance();
if ( $router->get_route('my_custom_routing') !== NULL ) { echo 'menu-active'; }

But you're right, there should be a template tag for that.

@ghost ghost assigned jbrinley Aug 9, 2013
@jonjhiggins
Copy link

I tried using your method as

$router = WP_Router::get_instance();
if ( $router->get_route('help-route-id') !== NULL ) {  echo 'Help section'; }

but "Help section" is output on to every page, not only the only ones routed through "help-route-id". This happened when placing the above code in either header.php or page.php.

Is there any other way to check the current route?

P.s. thanks for a great plugin 👍

@vwasteels
Copy link
Author

Hello,

I ended up doing like this :

// in header.php :
if(get_query_var('is_route_wiki') == 'true') echo 'menu-active';

// in functions.php :
$route_args = array(
                  'path'            => '^wiki',
                  'query_vars'      => array(
                    'is_route_wiki' => 'true'  // ***** this is the line ***
                    ),
                  'page_callback'   => 'empty_callback',
                  'page_arguments'  => array(),
                  'access_callback' => true,
                  'title'           => 'Wiki',
                  'template'        => array(
                    'templates/_wiki.php',
                    TEMPLATEPATH . 'templates/_wiki.php'
                )
              );
$router->add_route( 'wiki', $route_args );

@jonjhiggins
Copy link

Aah brilliant - that works for me! And thanks for the quick reply

@vwasteels
Copy link
Author

you're welcome !

@vwasteels
Copy link
Author

@jbrinley : do you plan adding an is_route('my-route'); template tag ? Just to know if I still need to use my hack with get_query_var() ... ;)

@jbrinley
Copy link
Owner

Stick with your code for now. I plan to add template tags in the future, and is_current_route() will be among them. But I can't give you a timeline. Pull requests are welcome. :)

@vwasteels
Copy link
Author

Ok good ! I'll try to do it, I let you know if I reach something ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants