Wordpress - 通过点击更改顺序

Wordpress - change order by on click

考虑到以下代码,我的 Wordpress 博客中有一个循环,它将帖子从旧到新排序。

<?php
    $args = array(
        'order'    => 'ASC'
    );
    query_posts( $args );
?>
<?php while ( have_posts() ) : the_post(); ?>
    <?php get_template_part('content'); ?> 
<?php endwhile; ?> 

我想要的是创建两个 links,用户点击并更改此参数,从旧到新或从新到旧。

我考虑过使用 jQuery 来实现这一点,但我不知道我将如何根据 link 用户点击来更改 PHP 代码。

如果您将排序方向更改为参数,例如

<?php
        $args = array(
            'order'    => (isset($_GET['dir']) ? $_GET['dir'] : 'ASC')
        );
        query_posts( $args );
    ?>

然后你可以创建一个 link 比如:

<a href="http:example.com/yourpage.php?dir=DESC">Newest to Oldest</a>
<a href="http:example.com/yourpage.php?dir=ASC">Oldest to Newest</a>