如果页面中的差异只是查询参数,则可以添加查询变量并在同一模板中使用它们:
//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;
}
 您的查询应如下所示:
<?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="<?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; ?>
 用户的链接应该是:
ASC:url+?p类型=bbp\\U主题(&U);my\\u sort=ASC描述:url+?p类型=bbp\\U主题(&U);my\\u sort=DESCNow 如果页面中的差异大于查询参数,则可以使用template_redirect 挂钩:
与之前相同添加查询参数
   //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;
    }
 然后向template\\u redirect挂钩添加一个函数,并基于该参数创建重定向:
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();
        }
    }
}
 您需要再次将参数添加到链接中,以便:
ASC:url+?my\\u sort=ASC描述:url+?my\\u sort=DESC