Trying to add post sort/order abilities to category.php

Best WordPress theme for game news websites, game portals or whatever your preferred subject.
GK User
Tue Nov 06, 2012 5:03 pm
I am trying to add sorting function in the category template.

I have come up with 2 diffrent things that I am pretty certain should work. But yet they dont..

here is my first attempt:

Code: Select all
<a href="http://mylocalhost/mysite/?orderby=date&order=asc" class="btn">A - Z</a>
      <a href="http://mylocalhost/mysite/?orderby=date&order=dsc" class="btn">Z - A</a>
      <a href="http://mylocalhost/mysite/games/league-of-legends/" class="btn">New</a>
      <a href="http://mylocalhost/mysite/games/league-of-legends/" class="btn">Old</a>
      <a href="http://mylocalhost/mysite/games/league-of-legends/" class="btn">Popular</a>


here is my second attempt:


Code: Select all
      <div class="sort">
   Sort by 
     <select onclick="if (this.value) { document.location = this.value; }"> 
        <option value="" selected="selected">Latest first</option> 
        <option value="<?php echo $short_page_url; ?>?orderby=date">Oldest first</option> 
        <option value="<?php echo $short_page_url; ?>?orderby=title">Titles A-Z</option> 
     </select>
</div>


What could the problem be?
User avatar
Junior Boarder

GK User
Tue Nov 06, 2012 11:29 pm
Hi,

did you tried to use in the select element the onchange event instead of the onclick?
User avatar
Administrator

GK User
Fri Nov 09, 2012 1:49 pm
That worked perfect!

Here is the code if anyone use it:

Code: Select all
<div class="sort">
   Sort by:
     <select onchange="if (this.value) { document.location = this.value; }"> 
        <option value="" selected="selected">Latest first</option> 
        <option value="<?php echo $short_page_url; ?>?orderby=date&order=dsc">Oldest first</option> 
        <option value="<?php echo $short_page_url; ?>?orderby=title&order=asc">Titles A-Z</option>
        <option value="<?php echo $short_page_url; ?>?orderby=title&order=dsc">Titles Z-A</option>
        <option value="<?php echo $short_page_url; ?>?orderby=comment_count&order=asc">Most Commented</option>
     </select>
</div>
User avatar
Junior Boarder


cron