Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.44 KB | None | 0 0
  1. Cat Parent
  2. -Cat Child 1
  3. -Cat Child 2
  4. -Cat Child 3
  5. -Cat Child 1
  6.  
  7. Cat Child 1
  8. -Post1 Child 1
  9. -Post2 Child 1
  10. -Post3 Child 1
  11. -So on... .
  12.  
  13. Cat Child 2
  14. -Post1 Child 2
  15. -Post2 Child 2
  16. -Post3 Child 2
  17. -So on... .
  18.  
  19. Cat Child 3
  20. -Post1 Child 3
  21. -Post2 Child 3
  22. -Post3 Child 3
  23. -So on... .
  24.  
  25. <?php $cats = get_categories('child_of='.get_query_var('cat'));
  26.  
  27. foreach ($cats as $cat) :
  28.  
  29. $args = array(
  30. 'posts_per_page' => 3, // max number of post per category
  31. 'category__in' => array($cat->term_id)
  32. );
  33. $my_query = new WP_Query($args);
  34.  
  35. if ($my_query->have_posts()) :
  36. echo '<h3>'.$cat->name.'</h3>';
  37.  
  38. while ($my_query->have_posts()) : $my_query->the_post(); ?>
  39. <?php /*general loop output; for instance: */ ?>
  40. <a href="<?php the_permalink() ?>"><?php the_title(); ?></a> <br />
  41.  
  42. <?php endwhile; ?>
  43.  
  44. <?php else :
  45. echo 'No Posts for '.$cat->name;
  46. endif;
  47.  
  48. endforeach; ?>
  49.  
  50. $taxonomy = 'product_cat';
  51. $category = get_terms($taxonomy);
  52.  
  53. echo '<ul>';
  54.  
  55. foreach( $category as $cat ){
  56. $link = get_term_link( $cat->slug, $taxonomy );
  57.  
  58. if(empty($cat->parent)){
  59. echo '<li><a href="' . $link . '">' . $cat->name . '</a>' . '<strong>' . $cat->count . '</strong></li>';
  60.  
  61. }
  62. $loop = 0;
  63.  
  64. foreach( $category as $par ){
  65. $link = get_term_link( $par->slug, $taxonomy );
  66. if($cat->term_id == $par->parent ){
  67.  
  68. if($loop == 0){ echo '<ul>'; }
  69. echo '<li><a href="' . $link . '">' . $par->name . '</a>' . $par->count . '</li>';
  70.  
  71. $loop++;
  72. }
  73. }
  74. if($loop > 0){ echo '</ul>'; }
  75.  
  76. }
  77.  
  78. echo '</ul>';
  79.  
  80. <ul class="catTags">
  81. <?php
  82. $args = array(
  83. 'show_option_all' => '',
  84. 'orderby' => 'count',
  85. 'order' => 'DESC',
  86. 'style' => 'list',
  87. 'show_count' => 0,
  88. 'hide_empty' => 1,
  89. 'use_desc_for_title' => 1,
  90. 'child_of' => 0,
  91. 'feed' => '',
  92. 'feed_type' => '',
  93. 'feed_image' => '',
  94. 'exclude' => 1,
  95. 'exclude_tree' => '',
  96. 'include' => '',
  97. 'hierarchical' => 1,
  98. 'title_li' => __( '' ),
  99. 'show_option_none' => __('No categories'),
  100. 'number' => null,
  101. 'echo' => 1,
  102. 'depth' => 2,
  103. 'current_category' => 0,
  104. 'pad_counts' => 0,
  105. 'taxonomy' => 'category',
  106. 'walker' => null
  107. );
  108.  
  109. wp_list_categories( $args );
  110. ?>
  111. </ul>
  112. </div>
  113.  
  114. <?php get_sidebar(); ?>
  115.  
  116. section .primary ul.catTags {
  117. padding:0px;
  118. }
  119.  
  120. section .primary ul.catTags li {
  121. float: left;
  122. list-style-type: none;
  123. margin: 0px 20px 10px 20px;
  124.  
  125. }
  126.  
  127. section .primary ul.catTags li a,section .primary ul.catTags li a:visited {
  128. font-size:18px;
  129. text-decoration:underline;
  130. }
  131. section .primary ul.catTags li a:hover {
  132. text-decoration:none;
  133. }
  134. section .primary ul.catTags li ul.children {
  135. max-width:200px;
  136. }
  137. section .primary ul.catTags li ul.children li {
  138. margin: 0px 5px 3px 5px;
  139. display: inline;
  140. }
  141. section .primary ul.catTags li ul.children li a, section .primary ul.catTags li ul.children li a:visited {
  142. font-size:14px;
  143. text-decoration:none;
  144. }
  145. section .primary ul.catTags li ul.children li a:hover {
  146. text-decoration:underline;
  147. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement