lundi 29 décembre 2014

custom template for custom url


I've tried registering an URL for which I want a custom template to load up (and list maybe ten or twelve items of a CPT I have already registered and have working elsewhere).


I have the following code:



public function url_for_calendar() {
add_rewrite_rule( 'events', 'index.php?upcoming-events=true', 'top' );
}

public function upcoming_event_query_var ( $vars ) {
$vars[]='upcoming-events';
return $vars;
}

public function template_for_calendar( $path ) {
if ( get_query_var( 'upcoming-events' ) ) {
$template = get_template_directory() . '/upcoming-events.php';
return $template;
}

return $path;
}


And the corresponding (it's all happening inside a class):



add_action ( 'init', array( $this, 'url_for_calendar' ) );
add_action ( 'query_vars', array( $this, 'upcoming_event_query_var' ) );
add_action ( 'template_redirect', array( $this, 'template_for_calendar' ) );


Custom URL is registered (yes, I resaved my permalink settings), and I can see in the debugger that I'm going through template_for_calendar and that the query_var is registered and caught, and that I'm returning the path for my custom template at the end of template_for_calendar... but instead of seeing that template I'm just getting home.php.


What I'm doing wrong here? Thanks and regards.





Aucun commentaire:

Enregistrer un commentaire