Support » Fixing WordPress » Create home page button to change sort order? (Child of Twenty Eleven)

  • Hi all.

    I’m an amateur enthusiast rather than a proper coder, but I’ve been successfully (if slowly :-))working my way through a number of customizations of Twenty Eleven using a child theme on an offline testing server, and I’ve now got the home page working pretty much as I’d like.

    My posts will be “pseudo-chronological”, so I want to give the visitor the option to switch the sort order of post excerpts on the home page with a button.

    I know how to change the sort order permanently, using…

    <?php global $query_string; query_posts($query_string . “&order=ASC”); ?>

    … at the start of the loop,
    and, from my research so far, it seems that creating two pages of posts, one with each sort order, with links to each other, might be the way to go.

    Is this the best way, do you think?
    Is it even possible?

    Any advice much appreciated.

    Many thanks,

Viewing 3 replies - 1 through 3 (of 3 total)
  • You could do that based on a URL variable via the $_GET parameter. No need in making another page. I’m not on my main computer or I’d write an example. Hope this gives you an idea at least.

    That sounds like the right solution Jerry, I’ll check it out.
    Many thanks,

    Just got around to testing this Jerry.
    Very simple, and works a treat.
    Much appreciated.

    For anyone else trying to do it…

    To change from default post sort order, then pass through URL as follows…
    (Note: case sensitive)

    Then, in Child version of index.php, after
    <?php /* Start the Loop */ ?>


    <!-- Change sort order using URL query string-->
        if ( $_GET['order'] == "ASC" ){
          global $query_string; query_posts($query_string . "&order=ASC");
        else {
          global $query_string; query_posts($query_string . "&order=DESC");

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Create home page button to change sort order? (Child of Twenty Eleven)’ is closed to new replies.