Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.72 KB | None | 0 0
  1. <?php
  2. /*
  3.  * Template Name: How To Sections
  4.  *
  5.  * Used to display all of the How To topics and their related posts
  6.  *
  7.  */
  8. ?>
  9. <?php get_header(); ?>
  10.       <div id="content">
  11.         <div id="page-preface" class="box">
  12. <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
  13.           <div id="page-head">
  14.           <?php if ( is_front_page() ) { ?>
  15.             <h2><?php the_title(); ?></h2>
  16.           <?php } else { ?>
  17.             <h1><?php the_title(); ?></h1>
  18.           </div>
  19.           <?php } ?>
  20.           <div id="page-text">
  21.             <?php the_content(); ?>
  22.           </div>
  23. <?php endwhile; endif; ?>
  24. <?php wp_reset_query(); ?>
  25.         </div>
  26.         <div id="how-to-list">
  27. <?php $cat = 'how-to';
  28. $catID = get_cat_ID($cat);
  29. $subcats = get_categories('parent=' . $catID);
  30. // Get list of subcats of How To Section
  31.   foreach($subcats as $subcat) {
  32.     $subcatID = get_cat_ID($cat_name);
  33.     $cat_name = $subcat->cat_name;
  34.     $page_name = get_page_by_title($cat_name);
  35.     if (get_categories('child_of=' . $subcatID) != '') {
  36. // Check if those subcats have children
  37.       $children_cats = get_categories('child_of=' . $subcatID);
  38. // Get subcat children
  39.       echo '<div class="how-to box">';
  40.       echo '<h2>case 1</h2>';
  41.       echo '<h2><a href="' . get_page_link($page_name->ID) . '">' . $subcat->cat_name . '</a></h2>';
  42.       foreach($children_cats as $child_cat) {
  43.         $child_subcatID = get_cat_ID("'" . $child_cat_name . "'");
  44.         $child_cat_name = $child_cat->cat_name;
  45.         $child_page_name = get_page_by_title($child_cat_name);
  46.         echo '<div class="how-to-child box">';
  47.         echo '<h3><a href="' . get_page_link($child_page_name->ID) . '">' . $child_cat->cat_name . '</a></h3>';
  48.         echo '<ul>';
  49.         $subcat_posts = get_posts('cat=' . $child_cat->cat_ID);
  50.         foreach($subcat_posts as $subcat_post) {
  51.           $postID = $subcat_post->ID;
  52.           echo '<li><a href="' . get_permalink($postID) . '">' . get_the_title($postID) . '</a></li>';
  53.         }
  54.         echo '</ul></div>';
  55.       }
  56.       echo '</div>';
  57.     }
  58.     else {
  59.       if (get_categories('child_of=' . $subcatID) == '') {
  60.         echo '<div class="how-to box">';
  61.         echo '<h2>case 2</h2>';
  62.         echo '<h2><a href="' . get_page_link($page_name->ID) . '">' . $subcat->cat_name . '</a></h2>';
  63.         echo '<ul>';
  64.         $subcat_posts = get_posts('cat=' . $subcat->cat_ID);
  65.         foreach($subcat_posts as $subcat_post) {
  66.           $postID = $subcat_post->ID;
  67.           echo '<li><a href="' . get_permalink($postID) . '">' . get_the_title($postID) . '</a></li>';
  68.         }
  69.       echo '</ul></div>';
  70.       }
  71.     }
  72.   } ?>
  73.         </div>
  74.       </div> <!-- #content -->
  75. <?php get_footer(); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement