Advertisement
Guest User

Untitled

a guest
Feb 19th, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.16 KB | None | 0 0
  1. <?php
  2.  
  3. $current_cat = get_query_var('cat');
  4. $attributes = array('terms_per_page' => 20, 'taxonomy' => 'category');
  5.  
  6. // Sanitize and validate our inputs and set variables
  7. $tpp = filter_var( $attributes['terms_per_page'], FILTER_VALIDATE_INT );
  8. $taxonomy = filter_var( $attributes['taxonomy'], FILTER_SANITIZE_STRING );
  9.  
  10. // Make sure our taxonomy exists to avoid unnecessary work
  11. if ( !taxonomy_exists( $taxonomy ) )
  12. return false;
  13.  
  14. // Our taxonomy exists, lets continue
  15. // Get the term count to calculate pagination.
  16. $term_count = count( get_terms('category',array('hide_empty'=>'1','child_of' => $current_cat) ) );
  17.  
  18. // We have terms, now calculate pagination
  19. $max_num_pages = ceil( $term_count / $tpp );
  20. // Get current page number. Take static front pages into account as well
  21. if ( get_query_var('paged')){
  22. $paged = get_query_var('paged');
  23. } elseif ( get_query_var('page')) {
  24. $paged = get_query_var( 'page' );
  25. } else {
  26. $paged = 1;
  27. }
  28. // Calculate term offset
  29. $offset = ( ( $paged - 1 ) * $tpp );
  30.  
  31. // We can now get our terms and paginate it
  32. $args = array(
  33. 'number' => $tpp, // Amount of terms to return
  34. 'offset' => $offset, // The amount to offset the list by for pagination
  35. 'child_of' => $current_cat,
  36. 'orderby' => 'name',
  37. 'order' => 'ASC',
  38. 'hide_empty' => '1',
  39. );
  40. // Set our variable to hold our string
  41. $output = '';
  42. $wpbtags = get_terms( $taxonomy, $args );
  43.  
  44. if ( ! empty($wpbtags)) {
  45. foreach ($wpbtags as $category) {
  46.  
  47. //first get the current category ID
  48. $cat_prefix = "category_";
  49. $cat_id = $category->term_id;
  50. //then i get the data from the database
  51. $join_cat = $cat_prefix . $cat_id;
  52. $cat_data = get_option($join_cat);?>
  53.  
  54. <a href="<?php echo get_category_link($category->term_id); ?>" onclick="ga('send', 'event', 'ClickNav', 'cats', 'Cat - <?php echo $category- >cat_name; ?>');">
  55. <div class="one_fourth<?php echo ( ++$counter == 4 )?' last_column':''; ?> home-colour" title="<?php echo $category->name; ?>">
  56.  
  57. <?php if (!empty($cat_data['cat_img_url'])) : ?>
  58. <h2 style="text-align:center"> <?php echo $category->name; ?> </h2>
  59. <img class="res_img" src="<?php echo $cat_data['cat_img_url'] ;?>" alt="<?php echo $category->cat_name; ?>" width="310" height="209" />
  60.  
  61. <?php elseif (empty($cat_data['cat_img_url'])) :?>
  62. <h2 style="text-align:center"> <?php echo $category->name; ?> </h2>
  63. <img class="res_img" src="<?php echo get_stylesheet_directory_uri(); ?>/images/subcat-img-na.png" alt="Posts - <?php echo $category->cat_name; ?>"/>
  64.  
  65. <?php else : ?>
  66. <?php endif; ?>
  67. </div><!-- eof cat div --> </a>
  68.  
  69. <?php } ?>
  70.  
  71. <?php /* COUNTS FOUR ADDS LAST COLUMN */ if ( $counter == 4 ) : ?>
  72. <div class='clear'> </div>
  73. <?php $counter = 0; endif; wp_reset_query(); ?>
  74.  
  75. <div class='clear'> </div>
  76.  
  77. <?php echo '<div class="wp-pagenavi" style="text-align:center">';
  78. $big = 999999999; // need an unlikely integer
  79. echo paginate_links( array(
  80. 'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
  81. 'format' => '?paged=%#%',
  82. 'current' => max( 1, get_query_var('paged') ),
  83. 'total' => $max_num_pages = (ceil( $term_count / $tpp))
  84. ) );
  85.  
  86. echo '</div>';
  87. ?>
  88.  
  89. <?php wp_reset_postdata(); ?>
  90.  
  91. <?php /* IF THERE'S NOTHING TO SHOW */ } else {?>
  92.  
  93. // Show something if there is no posts here
  94.  
  95. <?php } ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement