I've been fighting with looking to get this code focusing on my website. I must have the opportunity for that user to sort posts in climbing or climbing down order from clicking href link. This method ought to be appreciated once the user then selects to sort the publish list by an alternative choice e.g. title, votes, date.

Here's what I've got far:

<?php $sort= $_GET['sort'];
if($sort == "A")
$order= "gdsr_sort=thumbs";
if($sort == "B")
$order= "orderby=title";
if($sort == "C")
$order= "orderby=date";

<?php $updown= $_GET['updown'];

if($updown == "Y")
{$ascend= "ASC";} //this orders in ascending
if($updown == "Z")
{$ascend= "DESC";} //this orders in descending

<a href="?sort=A&updown=<?php echo $updown?>">Thumbs</a>
<a href="?sort=B&updown=<?php echo $updown?>">Author</a>
<a href="?sort=C&updown=<?php echo $updown?>">Date</a>

<?php $sort= isset($_GET['sort']) ? $_GET['sort'] : "B";

<a href="?updown=Y&sort=<?php echo $sort?>">Ascending</a>
<a href="?updown=Z&sort=<?php echo $sort?>">Descending</a>

<?php query_posts($order.'&order=$.ascend.'); ?>

        <?php if ( have_posts() ) : ?>
            <?php /* Start the Loop */ ?>
            <?php while ( have_posts() ) : the_post(); ?>

The href for sorting works all right nevertheless the ASC / DESC do nothing the entire factor just stays DESC.

Rather than using confusing letters, I'm able to suggest 2 better solutions:

  1. Make use of a base-3 number (1021021210) to find out which fields aren't sorted (), ASC (1) or DESC (2).
  2. Use PHP's $_GET superglobal and make Web addresses for example example.com/index.php?fielda=asc&fieldb=desc. Then parse it to determine exactly what the user desired to sort.

Solution 2 is preferred.

Far too complicated. Just keep user ASC/DESC preference inside a Cookie (via JS, if you need a quick&dirty solution), make use of the Cookie Value for Setting Order when sorting.