Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $_categories = get_categories( array(
- 'orderby' => 'order',
- 'order' => 'ASC',
- 'include' => array(2,3,4) // put the category IDs here
- ) );
- // Loop to display each of the Category
- foreach( $_categories as $_category ) :
- $_posts = get_posts( array(
- 'posts_per_page' => 6,
- 'category__in' => array( $_category->term_id ),
- 'ignore_sticky_posts' => 1,
- 'post_status' => 'publish'
- ) );
- if( $_posts ) :
- echo '<section id="category-'. intval($_category->term_id) .'" class="category-block">';
- echo '<h1 class="category-title">'. esc_html($_category->name) .'<h1>';
- echo '<div class="category-articles">';
- // Loop to display posts of certain a category
- foreach( $_posts as $post ) : setup_postdata( $post );
- echo '<article id="post-'. get_the_ID() .'" class="'. join( ' ', get_post_class( '', get_the_ID() ) .'">';
- echo '<a href="'. get_the_permalink() .'" rel="bookmark">'. get_the_title() .'</a>';
- echo '</article>';
- endforeach; wp_reset_postdata();
- echo '</div>';
- // A link to the Category archive
- echo '<a href="'. get_category_link( $_category->term_id ) .'" title="'. sprintf( esc_attr__( "View all posts in %s" ), $_category->name ) .'"></a>';
- echo '</section>';
- endif;
- endforeach;
Add Comment
Please, Sign In to add comment