WordPress.org

Ready to get started?Download WordPress

Forums

Create home page button to change sort order? (Child of Twenty Eleven) (4 posts)

  1. donal017
    Member
    Posted 1 year ago #

    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,
    Donal

  2. Jerry
    Member
    Posted 1 year ago #

    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.

  3. donal017
    Member
    Posted 1 year ago #

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

  4. donal017
    Member
    Posted 1 year ago #

    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...
    http://url.com/?order=ASC
    (Note: case sensitive)

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

    Enter...

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

Topic Closed

This topic has been closed to new replies.

About this Topic