0

I am using a custom URL on my menu to show the most viewed posts by passing the variables to the url as

http://website.com/?v_sortby=views&v_orderby=desc

However I want to use a custom template to display the results.

I tried the following but it doest work. I am having trouble finding a fix, can anyone help.

function custom_template($template) {
  global $wp;
  if ($wp->query_vars['template']=='basic') {
    return dirname( __FILE__ ) . '/basic.php';
  }
  else {
    return $template;
  }
}
add_filter('template_redirect', 'custom_template');
0

You'll have to exit afterwards.

add_filter( 'template_redirect', 'wpse85164_query_var_template' );
function wpse85164_query_var_template( $template )
{
    if ( 'basic' === get_query_var( 'template' ) )
        exit( dirname( __FILE__ ).'/basic.php' );

    return $template;
}
  • Still not working :(( I cant seem to figure out whats wrong. – David Garcia Feb 10 '13 at 16:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.