Advertisement
Guest User

function change_amt_archive

a guest
Feb 16th, 2012
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. <?php
  2. function add_jquery_to_head(){
  3. wp_deregister_script('jquery');// unregister default wp jquery
  4. wp_register_script('jquery','http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js');//set our version as the new jquery
  5. wp_enqueue_script('jquery');// then load it
  6. }
  7. add_action('template_redirect', 'add_jquery_to_head');
  8.  
  9. /* original sorting function from : http://blog.rutwick.com/use-jquery-to-reorder-your-wp-posts-on-the-fly */
  10. function change_amt_archive(){
  11. /* If this is a cat archive */
  12. if (is_category()){
  13. $cat = get_term_by('name', single_cat_title('',false), 'category');
  14. $archivetax ='category';
  15. $archivetype = $cat->slug;
  16. $catid = $cat->term_taxonomy_id;
  17. }//if cat
  18.  
  19. if( isset($_GET['a']) && $_GET['a'] != ''){
  20. $amt = $_GET['a'];
  21. switch($amt){
  22.  
  23. case '10':
  24. $amtper = '10';
  25. break;
  26.  
  27. case '50':
  28. $amtper = '50';
  29. break;
  30.  
  31. case 'all':
  32. $amtper = '-1';
  33. break;
  34. }}
  35. else{ //default
  36. $amtper = '10';
  37. }
  38. ?>
  39. Amount Per Page:
  40. <select id="amt-per">
  41. <option value="10" <?php echo (!isset($amt) || $amt == '' || $amt == '20')? 'selected="selected"':''; ?>>10</option>
  42. <option value="50" <?php echo ($amt == '50')? 'selected="selected"':''; ?>>50</option>
  43. <option value="all" <?php echo ($amt == 'all')? 'selected="selected"':''; ?>>View All</option>
  44. </select>
  45. <script type="text/javascript">
  46. var amtper = jQuery('#amt-per');
  47. var str;
  48. amtper.change(function(){
  49. str = jQuery(this).val();
  50. window.location.href = "<?php echo site_url(); ?>/<?php echo $archivetax ?>/<?php echo $archivetype ?>/?a="+str;
  51. });
  52. </script>
  53. <?php
  54. $args = array(
  55. 'cat' => $catid,
  56. 'posts_per_page' => $amtper
  57. );
  58. query_posts( $args );
  59. ?>
  60.  
  61. <?php
  62. }//end change_amt_archive
  63. ?>
  64.  
  65.  
  66. <?php /* temlate tag - paste above archive loop in archive.php template
  67. if(function_exists('change_amt_archive')) :
  68. change_amt_archive();
  69. endif;
  70. */ ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement