Advertisement
srikat

page_categories_table.php

Sep 17th, 2014
287
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.79 KB | None | 0 0
  1. <?php
  2. /*
  3.     Template Name:  Categories Table
  4. */
  5.  
  6. # Force full width content
  7. add_filter( 'genesis_pre_get_option_site_layout', '__genesis_return_full_width_content' );
  8.  
  9. # Remove the post content
  10. remove_action( 'genesis_entry_content', 'genesis_do_post_content' );
  11. # Add custom post content
  12. add_action( 'genesis_entry_content', 'sk_do_post_content' );
  13.  
  14. /**
  15.  * Outputs custom post content
  16.  *
  17.  * @return void
  18.  */
  19. function sk_do_post_content() {
  20.  
  21.     $cat_args = array(
  22.                 'orderby' => 'name',
  23.                 // 'parent' => 0
  24.                 );
  25.  
  26.     $categories = get_categories( $cat_args );
  27.  
  28.     foreach ( $categories as $category ) {
  29.         echo '<div class="category-item">';
  30.  
  31.             // Category title
  32.             echo '<h2 class="category-title"><a href="' . get_category_link( $category->term_id ) . '">' . $category->name . '</a></h2>';?>
  33.  
  34.             <table>
  35.                 <thead>
  36.                     <tr>
  37.                         <th>Title</th>
  38.                         <th>Author</th>
  39.                         <th>Date</th>
  40.                         <th>Tags</th>
  41.                         <th>Views</th>
  42.                     </tr>
  43.                 </thead>
  44.                 <tbody>
  45.  
  46.                     <?php
  47.  
  48.                     $args = array(
  49.                                 'orderby' => 'title',
  50.                                 'order' => 'ASC',
  51.                                 // 'category__in' => array($category->term_id),
  52.                                 'cat' => $category->term_id,
  53.                                 'posts_per_page' => -1
  54.                                 );
  55.  
  56.                     // The Query
  57.                     $the_query = new WP_Query( $args );
  58.  
  59.                     while ( $the_query->have_posts() ) {
  60.                         $the_query->the_post();
  61.  
  62.                     ?>
  63.  
  64.                     <tr>
  65.                         <td><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></td>
  66.                         <td><?php the_author_link(); ?></td>
  67.                         <td><?php the_date(); ?></td>
  68.                         <td><?php the_tags(); ?></td>
  69.                         <td>No. of Views</td>
  70.                     </tr>
  71.  
  72.                     <?php }
  73.  
  74.                     /* Restore original Post Data */
  75.                     wp_reset_postdata(); ?>
  76.                 </tbody>
  77.             </table>
  78.  
  79.             <?php
  80.         echo '</div><!-- .category-item -->';
  81.     }
  82.  
  83. }
  84.  
  85. genesis();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement