If the differences in the pages are just query arguments the you can add query vars and use them in the same template:
//add your arguments to query vars
add_filter('query_vars', 'my_query_vars');
function my_query_vars($vars) {
// add my_sortand ptype to the valid list of variables you can add as many as you want
$new_vars = array('my_sort','ptype');
$vars = $new_vars + $vars;
return $vars;
}
your query should look like this:
<?php $custom_posts = new WP_Query(); ?>
<?php $custom_posts->query(array('post_type' => get_query_var('ptype'), 'order' => get_query_var('my_sort'))); ?>
<?php while ($custom_posts->have_posts()) : $custom_posts->the_post(); ?>
<div class="content-block-2">
<a href="https://wordpress.stackexchange.com/questions/13086/<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'twentyten' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a>
</div>
<?php endwhile; ?>
and you links for the user should be:
- ASC: url + ?ptype=bbp_topic&my_sort=ASC
- DESC: url + ?ptype=bbp_topic&my_sort=DESC
Now if your differences in the pages are more then query arguments you can change the template page using template_redirect
hook:
same as before add your query arg
//add your arguments to query vars
add_filter('query_vars', 'my_query_vars');
function my_query_vars($vars) {
// add my_sort to the valid list of variables
$new_vars = array('my_sort');
$vars = $new_vars + $vars;
return $vars;
}
then add a function to the template_redirect hook and create the redirection based of that argument:
add_action("template_redirect", 'sort_template_redirect');
// Template selection
function sort_template_redirect()
{
global $wp;
global $wp_query;
if (isset($wp->query_vars["my_sort"]))
{
// Let's look for the template file in the current theme
if (array_key_exists('my_sort', $wp->query_vars) && $wp->query_vars['my_sort'] == 'ASC'){
include(TEMPLATEPATH . '/single-asc.php');
die();
}
if (array_key_exists('my_sort', $wp->query_vars) && $wp->query_vars['my_sort'] == 'DESC'){
include(TEMPLATEPATH . '/single-desc.php:');
die();
}
}
}
and once again you will need to add the args to the link so:
- ASC: url + ?my_sort=ASC
- DESC: url + ?my_sort=DESC