Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Does anyone know how to make this page template to only show knowledgebase post types? I've tried various different ways but with no luck

<?php
  $cat_args = array(
  'taxonomy' => 'knowledgebase_category', 
 'orderby' => 'slug',
 'order' => 'ASC',
 'hierarchical' => true,
 'parent' => 0,
  'child_of' => 0
  );

 $categories = get_categories($cat_args); 
 $catCounter = 7;
 foreach($categories as $category) { 
 $catCounter++;
 if ($catCounter == 1) { 
 echo '</div><div class="row knowledge-base">';
 } 
 elseif ($catCounter == 8) {
 $catCounter = 1;
 echo '<div class="row knowledge-base">';
 }
 elseif ($catCounter == 3) { 
 $catCounter = 0;
 } 

 echo '<div class="span3">';
 echo '<h2><a href="' . get_category_link( $category->term_id ) . title="'            .         $category->name . '" ' . '>' . $category->name.'</a></h2>';

// Sub category
$sub_category = get_category($category);
$subcat_args = array(
'orderby' => 'name',
'order' => 'ASC',
'child_of' => $sub_category->cat_ID,
'parent' => $sub_category->cat_ID
 );
 $sub_categories = get_categories($subcat_args); 

 foreach($sub_categories as $sub_category) { 
echo '<ul class="sub-categories">';
echo '<li><i class="icon-folder-close"></i> <a href="' . get_category_link(          $sub_category->term_id ) . '" title="' . $sub_category->name .     '" ' . '>' . $sub_category->name.'</a></li>';
echo '</ul>';
    }


    //List Posts

    // Smart Lists
    $cat_post_num = gt_get_option('kb_aticles_per_cat');

    $sub_category_num = count($sub_categories);
    if ($sub_category_num != 0) {
    $cat_post_num_smart = $cat_post_num - $sub_category_num;
     } else {
    $cat_post_num_smart = $cat_post_num;    
    }
    $posts_order = '' ;// of_get_option('st_hp_cat_posts_order');


   global $post;
    // Listed by popular?
    $cat_post_args = array(
      'post_type' => 'knowledgebase',
   'numberposts' => $cat_post_num_smart,
      'orderby' => $posts_order,

     );

    $cat_posts = get_posts($cat_post_args);
    echo '<ul class="category-posts">';
    foreach($cat_posts as $post) : setup_postdata($post);
    if (get_post_format() == 'video') {
    $post_icon = 'icon-film';
    } elseif (get_post_format() == 'image') {
     $post_icon = 'icon-picture';
    } else {
    $post_icon = 'icon-file';
     }
    ?>

      <li><i class="<?php echo $post_icon; ?>"></i> <a href="<?php the_permalink();       ?>"><?php the_title(); ?></a></li>

   <?php 
endforeach;
echo '</ul>';
     echo '<span class="label label-color"><a href="' . get_category_link(                 $category->term_id ) . '" title="" ' . '>View all ' .     $category->count .' articles <i class="icon-chevron-right"></i></a></span>';
    echo '</div>';
     } 
   ?>
share|improve this question
add comment

2 Answers

From what I can understand of your snippet post retrieval is implemented by get_posts($cat_post_args) call and so results are controlled by $cat_post_args arguments.

To add post type limitation to it you should add post_type argument to that array. See documentation on get_posts() and WP_Query (used internally and documents available argument more thoroughly).

share|improve this answer
    
hi i tried 'post_type' => 'knowledgebase', in $cat_post_args im afraid that didn't work <?php $cat_args = array( 'post_type' => 'knowledgebase', 'orderby' => 'slug', 'order' => 'ASC', 'hierarchical' => true, 'parent' => 0, 'child_of' => 0 ); –  user31891 May 4 '13 at 20:04
    
And?.. :) Did it work? –  Rarst May 4 '13 at 20:05
    
no sorry it didn't –  user31891 May 4 '13 at 20:09
    
i also tried 'post_type' => array('knowledgebase'), and that didnt work –  user31891 May 4 '13 at 20:18
    
I've modified the code above to reflect the changes made, so far i can see the categories and posts, but not the correct posts to the correct categories –  user31891 May 5 '13 at 9:21
add comment
up vote 0 down vote accepted

Had to do a complete rewrite in the end also using a complete different post type approach

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.