Advertisement
pjerky

Output Wordpress Categories and Posts Removing Duplicates

Nov 11th, 2014
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.39 KB | None | 0 0
  1. <?php
  2. $url = explode('/',$_SERVER['REQUEST_URI']);
  3. $dir = $url[2] ? $url[2] : 'UX-Style-Guide';
  4. $result = str_replace ("?", "", $dir);
  5. $final = current(explode('=', $result));
  6. $style = str_replace ("-", " ", $final);
  7. $style = ucwords($style);
  8. $post_id = $post->ID;
  9. $class = '';
  10. ?>
  11.  
  12. <!-- THIS IS THE LEFTNAV -->
  13. <nav id="verticalNav" class="ui-side-nav-drawer">
  14.     <div class="cssmenu">
  15.         <div id="entry-search">
  16.             <input type="text" placeholder="Search Styleguide Entries" class="fuzzy-search" />
  17.         </div>
  18.         <ul class="list">
  19.             <?php
  20.             $nav_cat_args = array(
  21.                 'orderby' => 'name',
  22.                 'order' => 'ASC',
  23.                 'child_of' => 0,
  24.                 'exclude'=> 1
  25.             );
  26.  
  27.             $nav_categories =   get_categories($nav_cat_args);
  28.             $displayedPosts = array();
  29.  
  30.             foreach($nav_categories as $category) {
  31.                 echo "<li><span class='navAppTitle'>" . $category->name . "</span></li>\n";
  32.                
  33.                  $nav_post_args = array(
  34.                       'numberposts' => -1,
  35.                       'category' => $category->term_id,
  36.                       'post_type' => $final,
  37.                       'orderby' => 'name',
  38.                       'order' => 'ASC',
  39.                       'child_of' => 0  
  40.                  );
  41.  
  42.                 $nav_posts = get_posts($nav_post_args);
  43.                
  44.                 foreach($nav_posts as $post) {
  45.                     if (in_array($post->ID, $displayedPosts)) {
  46.                         continue; //Skip this post if it has already been displayed once.
  47.                     }
  48.  
  49.                     $title = the_title();
  50.                     $link = the_permalink();
  51.  
  52.                     $displayedPosts[] = $post->ID;
  53.                     $class = '';
  54.  
  55.                     if ($post_id == $post->ID) {
  56.                         $class = 'entry-title current';
  57.                     } else {
  58.                         $class = 'entry-title';
  59.                     }
  60.  
  61.                     echo "<li class='$class'>";
  62.                     echo "<a class='entry-link' href='{$link}'>{$title}</a>";
  63.                     echo "</li>\n";
  64.                 }
  65.             }
  66.             ?>
  67.  
  68.             <?php wp_reset_query(); ?>
  69.             <div id="job-listings"></div>
  70.         </ul>
  71.     </div>
  72. </nav><!-- /END #verticalNav -->
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement