Guest User

Untitled

a guest
Feb 25th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. <?php
  2. // Check parent category, check if parent category has sub categories, display sub categories of parent that have posts associated.
  3. $term = get_field('parent_category');
  4. if ($term) {
  5. $args = ['parent' => $term];
  6. $categories = get_categories($args);
  7.  
  8. if (!empty($categories)) {
  9.  
  10. echo '<div class="child-categories widget widget_categories">';
  11. echo '<h4>Categories</h4>';
  12. echo '<ul>';
  13. foreach ($categories as $category) {
  14. echo '<li><a href="' . get_category_link($category->term_id) . '" title="' . sprintf(__("View all posts in %s"), $category->name) . '" ' . '>' . $category->name . '</a></li>';
  15. }
  16. echo '</ul>';
  17. echo '</div>';
  18. }
  19. else {
  20.  
  21. dynamic_sidebar('sidebar1');
  22. }
  23. }
  24. ?>
Add Comment
Please, Sign In to add comment