Advertisement
gregrickaby

Get CPT Category

Feb 1st, 2012
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.12 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4. remove_action( 'genesis_loop', 'genesis_do_loop' ); // Remove default Genesis Loop
  5. add_action( 'genesis_loop', 'child_cpt_post_loop' ); // Add custom post type loop
  6. /**
  7.  * Build the custom loop to display project category
  8.  *
  9.  * @author Greg Rickaby
  10.  * @since 1.0.0
  11.  */
  12. function child_cpt_post_loop() {
  13.  
  14.     if ( is_category() ) {
  15.         $cat = get_query_var( 'cat' );
  16.         $cptcat = get_category($cat);
  17.         $cptcat->slug;
  18.     }
  19.  
  20.     $loop = new WP_Query( array(
  21.         'post_type' => 'project',
  22.         'posts_per_page' => 20,
  23.         'category_name' => $cptcat->slug,
  24.     ) );
  25.    
  26.     while ( $loop->have_posts() ) : $loop->the_post(); ?>
  27.                 <div class="post-<?php the_ID(); ?> post project project-category">
  28.                     <div class="entry-content">
  29.                     <?php // Check for download link
  30.                         if ( genesis_get_custom_field( '_cmb_project_download' ) ) { ?>
  31.                     <div class="project-download">
  32.                         <a href="<?php echo genesis_get_custom_field( '_cmb_project_download' ); ?>" title="<?php the_title();?>" class="sfdl">
  33.                             <span>
  34.                                 <b>Download</b>
  35.                                 <small><?php the_title(); ?></small>
  36.                             </span>
  37.                         </a>
  38.                     </div>
  39.                     <?php } ?>
  40.  
  41.                     <h1 class="entry-title">
  42.                     <?php // Check for icon
  43.                         if ( genesis_get_custom_field( '_cmb_project_icon' ) ) { ?>
  44.                     <div class="project-icon">
  45.                             <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><img src="<?php echo genesis_get_custom_field( '_cmb_project_icon' ); ?>" title="<?php the_title();?>" alt="<?php the_title();?>" height="48" width="48" class="the-icon" /></a>
  46.                     </div>
  47.                     <?php } ?>
  48.                         <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h1>
  49.  
  50.                     <?php // Check for short description
  51.                         if ( genesis_get_custom_field( '_cmb_project_short_description' ) ) { ?>
  52.                             <div class="project-short-description">
  53.                                 <?php echo genesis_get_custom_field( '_cmb_project_short_description' ); ?>
  54.                             </div>
  55.                     <?php } ?>
  56.                     </div>
  57.                     <!-- end .entry-content -->
  58.                 </div>
  59.                 <!-- end .post -->
  60.     <?php endwhile; wp_reset_query();
  61. }
  62.  
  63. /** Finish loading the page */
  64. genesis();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement