Advertisement
srikat

template_news.php

Oct 7th, 2016
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4. * Template Name: News Template
  5. * Description: Used as a page template to show page contents, followed by a loop through
  6. * each non-empty category that has at least 1 published post and displays the latest posts'
  7. * content and featured image with a link to the category archive page below the list.
  8. */
  9.  
  10. add_action( 'genesis_entry_content', 'sk_custom_content' );
  11. function sk_custom_content() {
  12.  
  13. $categories = get_categories();
  14.  
  15. echo '<div class="category-loop">';
  16.  
  17. foreach ( $categories as $category ) {
  18. echo '<div class="category-item">';
  19.  
  20. // Category title
  21. echo '<h3 class="category-title">' . $category->name . '</h3>';
  22.  
  23. $args = array(
  24. 'cat' => $category->term_id,
  25. 'posts_per_page' => 3
  26. );
  27.  
  28. // The Query
  29. $the_query = new WP_Query( $args );
  30.  
  31. while ( $the_query->have_posts() ) {
  32. $the_query->the_post();
  33. echo '<div class="cat-listing ' . $category->slug . '-item">';
  34. echo '<h4>'. get_the_title() . '</h4>';
  35.  
  36. echo '<p class="cat-date entry-meta">';
  37. echo the_date();
  38. echo '</p>';
  39.  
  40. if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
  41. the_post_thumbnail( 'full', array( 'class' => 'alignright' ) );
  42. }
  43.  
  44. // echo the_content();
  45. echo the_excerpt();
  46.  
  47. if( function_exists( 'social_warfare' ) ):
  48. social_warfare();
  49. endif;
  50. echo '</div>';
  51. }
  52.  
  53. echo '<a class="category-more" href="' . get_category_link( $category->term_id ) . '">More from the "' . $category->name . '" category …</a>';
  54.  
  55. /* Restore original Post Data */
  56. wp_reset_postdata();
  57.  
  58. echo '</div><!-- .category-item -->';
  59. }
  60.  
  61. echo '</div>';
  62.  
  63. }
  64.  
  65. genesis();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement