Guest User

Untitled

a guest
Jan 19th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. <?php
  2. $_categories = get_categories( array(
  3. 'orderby' => 'order',
  4. 'order' => 'ASC',
  5. 'include' => array(2,3,4) // put the category IDs here
  6. ) );
  7.  
  8. // Loop to display each of the Category
  9. foreach( $_categories as $_category ) :
  10.  
  11. $_posts = get_posts( array(
  12. 'posts_per_page' => 6,
  13. 'category__in' => array( $_category->term_id ),
  14. 'ignore_sticky_posts' => 1,
  15. 'post_status' => 'publish'
  16. ) );
  17.  
  18. if( $_posts ) :
  19.  
  20. echo '<section id="category-'. intval($_category->term_id) .'" class="category-block">';
  21.  
  22. echo '<h1 class="category-title">'. esc_html($_category->name) .'<h1>';
  23.  
  24. echo '<div class="category-articles">';
  25.  
  26. // Loop to display posts of certain a category
  27. foreach( $_posts as $post ) : setup_postdata( $post );
  28. echo '<article id="post-'. get_the_ID() .'" class="'. join( ' ', get_post_class( '', get_the_ID() ) .'">';
  29. echo '<a href="'. get_the_permalink() .'" rel="bookmark">'. get_the_title() .'</a>';
  30. echo '</article>';
  31. endforeach; wp_reset_postdata();
  32.  
  33. echo '</div>';
  34.  
  35. // A link to the Category archive
  36. echo '<a href="'. get_category_link( $_category->term_id ) .'" title="'. sprintf( esc_attr__( "View all posts in %s" ), $_category->name ) .'"></a>';
  37.  
  38. echo '</section>';
  39.  
  40. endif;
  41.  
  42. endforeach;
Add Comment
Please, Sign In to add comment