Guest User

Custom Category template

a guest
Sep 14th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.71 KB | None | 0 0
  1. <?php
  2. /**
  3.  * This is Category file.
  4.  *
  5.  * @package  Genesis-Child-Theme
  6.  * @since    1.0.0
  7.  */
  8.  
  9. /**
  10.  * Genesis custom loop
  11.  */
  12. /** Replace the standard loop with our custom loop */
  13. remove_action ('genesis_loop', 'genesis_do_loop'); // Remove the standard loop
  14. add_action( 'genesis_loop', 'custom_do_press_loop' ); // Add custom loop
  15.  
  16. function custom_do_press_loop() {
  17.     $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
  18.     $args = array(
  19.         'post_type'         => 'post',
  20.         'cat'               => 'category_name',
  21.         'posts_per_page'    => 3,
  22.         'orderby'           => 'date',
  23.         'order'             => 'DSC',
  24.         'paged'             => $paged
  25.     );
  26.  
  27. echo '<section>';
  28.     /*
  29.     Overwrite $wp_query with our new query.
  30.     The only reason we're doing this is so the pagination functions work,
  31.     since they use $wp_query. If pagination wasn't an issue,
  32.     use: https://gist.github.com/3218106
  33.     */
  34.     global $wp_query;
  35.     $temp = $wp_query;
  36.     $wp_query = new WP_Query( $args );
  37.     if( have_posts() ):
  38.  
  39.         while( have_posts() ): the_post();
  40.             global $post;
  41.  
  42.             echo '<article>';
  43.  
  44.             echo '<div class="entry-content grey">';
  45.  
  46.               echo '<header class="entry-header block-link-entry-header">';
  47.                 echo '<h2 class="entry-title block-link-entry-title">' . get_the_title() . '</h2>';
  48.               echo '</header>';
  49.  
  50.               echo '<p>' . get_the_date() . '</p>';
  51.  
  52.               echo '<p>'  . get_the_excerpt() . '</p>';
  53.  
  54.             echo '</div>';
  55.  
  56.               echo '<a href="' . get_permalink() . '" class="block-link image-block-link">';
  57.  
  58.                 echo get_the_post_thumbnail();
  59.  
  60.               echo '</a>';
  61.  
  62.             echo '</article>';
  63.  
  64.                     endwhile;
  65.                     do_action( 'genesis_after_endwhile' );
  66.  
  67.             echo '</section>';
  68.  
  69.         wp_reset_query();
  70.  
  71.       endif;
  72.      
  73.     $wp_query = $temp;
  74. }
  75.  
  76. genesis();
Add Comment
Please, Sign In to add comment