I have been battling with trying to get this code working on my site. I would like to have the ability for the user to sort posts in ascending or descending order from clicking href link. This option should be remembered when the user then chooses to sort the post list by another option e.g. title, votes, date.
Here is what I have 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 just fine however the ASC / DESC do not do anything the whole thing just stays DESC.