Display categories with the last five posts under

Hi

Thanks for all the good plugins. Keep the good work up!

I need help on a code to see all the categories in my custom post type with the last five entries in each category below. So it goes first in the first category, pushing out five posts, then to the next category, until there are no more categories.

Is that possible?

  • Fuga Group AS
    • New Recruit

    Hi

    I am trying to create a knowledge base with different categories that have many posts. I'm trying to make a front page for it by automatically pulling out all the categories of the custom post type, and display the tittle and link for the last five items under each category.

    So it will automatically add new lists, when we create new categories and items.

  • Fuga Group AS
    • New Recruit

    Hi. That plugin worked fine, but i found another solution her without a plugin and you got full control over all parameters.

    <?php
    //for each category, show 5 posts
    $cat_args=array(
      'orderby' => 'name',
      'order' => 'ASC',
       );
    $categories=get_categories($cat_args);
      foreach($categories as $category) {
        $args=array(
          'showposts' => 5,
          'post_type' => 'YOUR COSTUM POST TYPE',
          'category__in' => array($category->term_id),
          'caller_get_posts'=>1
        );
        $posts=get_posts($args);
          if ($posts) {
            echo '<p>Category: <a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a> </p> ';
            foreach($posts as $post) {
              setup_postdata($post); ?>
              <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
              <?php
            } // foreach($posts
          } // if ($posts
        } // foreach($categories
    ?>
  • Fuga Group AS
    • New Recruit

    And if your using custom taxanomy with custom posts

    <?php
    $post_type = 'POSTYPE';
    
    // Get all the taxonomies for this post type
    $taxonomies = get_object_taxonomies( (object) array( 'post_type' => $post_type ) );
    
    foreach( $taxonomies as $taxonomy ) : 
    
        // Gets every "category" (term) in this taxonomy to get the respective posts
        $terms = get_terms( $taxonomy );
    
        foreach( $terms as $term ) :
          echo '<span>' . $term->name.'</span>';
            $posts = new WP_Query( "taxonomy=$taxonomy&term=$term->slug&posts_per_page=5" );
    
            if( $posts->have_posts() ): while( $posts->have_posts() ) : $posts->the_post(); ?>
               <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
            <?php endwhile; endif;
    
        endforeach;
    
    endforeach;
    ?>

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.