• hi,

    i have a website that running wordpress. i have a category page that list all the book i’ve review and it’s in category ‘Book’ (the category ID is 4) and in the top op the page i have a dropdown list that will sort the list based on title or date.

    This is what i did:

    http://wordpress.pastebin.ca/940717

    what i want to do is, instead of sorting the list based on title or date, it would be useful for user to sort it based on categories like Romance, Interior, Fiction, Food. (they’re subcategories from ‘Book’ category).

    So I try change the dropdown with the dropdown mentioned in this codex: http://codex.wordpress.org/Function_Reference/get_categories

    And now the codes become:
    http://wordpress.pastebin.ca/940720

    Somehow I can’t make it right. I test on my localhost and the list remains the same. it’s not sort them out based on the subcategories.

    So if anyone have some ideas, i really appreciate it. thanks.

Viewing 1 replies (of 1 total)
  • Thread Starter soyuz

    (@soyuz)

    well, i think i will make another way. since this page is outside the wordpress, i assume it can’t be done.

    now i’m trying to use the dropdown and make it jump to ‘same’ pages. i made one page for each value. i put this line for each page:
    <?php query_posts('cat=21&posts_per_page=-1&orderby=' . $order_by . '&order=desc'); ?>

    and change the “cat” value for each pages.

    i still use the same dropdown:

    <select name="event-dropdown" onchange='document.location.href=this.options[this.selectedIndex].value;'>
     <option value=""><?php echo attribute_escape(__('Select Event')); ?></option>
     <?php
      $categories=  get_categories('child_of=10');
      foreach ($categories as $cat) {
      	$option = '<option value="/category/archives/'.$cat->category_nicename.'">';
    	$option .= $cat->cat_name;
    	$option .= ' ('.$cat->category_count.')';
    	$option .= '</option>';
    	echo $option;
      }
     ?>
    </select>

    what i want to do is, to put ‘selected=”selected”‘ inside the option when it’s on the selected page. i don’t understand PHP but i tried to modified like this:

    <select name="event-dropdown" onchange='document.location.href=this.options[this.selectedIndex].value;'>
     <option value=""><?php echo attribute_escape(__('Select Event')); ?></option>
     <?php
      $categories=  get_categories('child_of=10');
      foreach ($categories as $cat) {
      	$option = '<option value="/category/archives/'.$cat->category_nicename.'" if ($cat == category_nicenames) echo ('selected="selected"')>';
    	$option .= $cat->cat_name;
    	$option .= ' ('.$cat->category_count.')';
    	$option .= '</option>';
    	echo $option;
      }
     ?>
    </select>

    of course it doesn’t work :). so if someone can give suggestions, i really appreciate it.

    thanks.

Viewing 1 replies (of 1 total)
  • The topic ‘Let user choose to sort the order’ is closed to new replies.