Advertisement
marjwyatt

CPT Archive List - Genesis

Sep 14th, 2014
333
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.47 KB | None | 0 0
  1. <?php
  2. /* Template Name: Stories List
  3. * Description: Displays Professions with list of stories and link to custom taxonomy archive
  4. * Author: Marj Wyatt aka Virtually Marj
  5. *
  6. * Schema http://schema.org/ItemList
  7. */
  8.  
  9. if ( !is_user_logged_in() ) {
  10.     wp_redirect( home_url('/oops-this-content-is-members-only') );
  11.     exit;
  12. }
  13. remove_action ('genesis_loop', 'genesis_do_loop'); // Remove the standard loop
  14. add_action( 'genesis_loop', 'vm_stories_archive' ); // Add custom loop
  15. //add_filter( 'genesis_pre_get_option_site_layout', '__genesis_return_full_width_content' ); // Force full page layout
  16. /*add_filter( 'genesis_attr_body', 'vm_list_schema' ); // Customize Schema Markup
  17. function vm_list_schema() {
  18.   $attributes['itemtype'] = 'http://schema.org/ItemList';
  19.   return $attributes;
  20. }*/
  21.  
  22. function vm_stories_archive() {
  23.     echo '<div class="cities">';
  24.     $argsCity = array(
  25.         'smallest'                  => 16,
  26.         'largest'                   => 16,
  27.         'unit'                      => 'px',
  28.         'number'                    => 50,
  29.         'format'                    => 'flat',
  30.         'separator'                 => "&#183;",
  31.         'orderby'                   => 'name',
  32.         'order'                     => 'ASC',
  33.         'exclude'                   => null,
  34.         'include'                   => null,
  35.         'topic_count_text_callback' => default_topic_count_text,
  36.         'link'                      => 'view',
  37.         'taxonomy'                  => 'city',
  38.         'echo'                      => true,
  39.         'child_of'                  => null, // see Note!
  40.     );
  41.     echo '<h4 class="widget-title">Peruse by City</h4>';
  42.     wp_tag_cloud( $argsCity );
  43.     echo '</div>';
  44.     echo '<div class="states">';
  45.     $argsState = array(
  46.         'smallest'                  => 16,
  47.         'largest'                   => 16,
  48.         'unit'                      => 'px',
  49.         'number'                    => 50,
  50.         'format'                    => 'flat',
  51.         'separator'                 => "&#183;",
  52.         'orderby'                   => 'name',
  53.         'order'                     => 'ASC',
  54.         'exclude'                   => null,
  55.         'include'                   => null,
  56.         'topic_count_text_callback' => default_topic_count_text,
  57.         'link'                      => 'view',
  58.         'taxonomy'                  => 'state',
  59.         'echo'                      => true,
  60.         'child_of'                  => null, // see Note!
  61.     );
  62.     echo '<h4 class="widget-title">Peruse by State</h4>';
  63.     wp_tag_cloud( $argsState );
  64.     echo '</div>';
  65.     echo '<p>&nbsp;</p>';
  66.     echo '<div class="story-content" itemscope="itemscope" itemtype="http://schema.org/ItemList">';
  67.     $profession_terms = get_terms( 'professions', array(
  68.         'orderby'    => 'count',
  69.         'order' => 'DESC',
  70.         'hide_empty' => 0
  71.     ) );
  72.     foreach( $profession_terms as $term ) {
  73.     $count = $term->count;
  74.     $term_link = get_term_link( $term );
  75.     $blogurl = get_bloginfo('url');
  76.     // Define the query
  77.     $args1 = array(
  78.         'posts_per_page' => -1,
  79.         'post_type' => 'shows',
  80.         'professions' => $term->slug
  81.     );
  82.     $myQuery = new WP_Query( $args1 );
  83.     if ( $count == 1 ) {
  84.         $label = 'Story'; }
  85.     if (  ( $count > 1 ) || ( $count == 0 ) ) {
  86.         $label = 'Stories';
  87.     }
  88.     echo '<h2 itemprop="name"><a href="' . $term_link .'">' . $term->name . '</a><span class="entry-meta"> (' . $count . ' ' . $label . ')</span></h2>';
  89.     echo '<meta itemprop="itemListOrder" content="Unordered" />';
  90.     if ( $count == 0 ) {
  91.         echo '<p>No stories found.</p>';
  92.         echo '<p class="postlist-entry-meta">Be the first to <a href="' . $blogurl . '/add-your-story/">add your <b>' . $term->name . '</b> story</a>!</p>';
  93.     }
  94.     while ( $myQuery->have_posts() ) : $myQuery->the_post();
  95.         $postID = get_the_ID();
  96.         $postDate = get_the_date('', $post->ID);
  97.         $postTerms = wp_get_post_terms($postID, 'city', array("fields" => "all"));
  98.         $postCity = $postTerms[0]->slug;
  99.         $postCityName = $postTerms[0]->name;
  100.         $cityLinkConstruct = $blogurl . '/cities/' . $postCity;
  101.         $postCityLink = '<a href="' . $cityLinkConstruct . '">' . $postCityName . '</a>';
  102.         $postStateTerms = wp_get_post_terms($postID, 'state', array("fields" => "all"));
  103.         $postState = $postStateTerms[0]->slug;
  104.         $postStateName = $postStateTerms[0]->name;
  105.         $stateLinkConstruct = $blogurl . '/states/' . $postState;
  106.         $postStateLink = '<a href="' . $stateLinkConstruct . '">' . $postStateName . '</a>';
  107.         echo '<ul class="ckicon">';
  108.         echo '<hr>';
  109.         echo '<li itemprop="itemListElement">';
  110.         echo '<span itemprop="url"><a href="' . get_post_permalink($postID) .'" rel="bookmark" title="' . get_the_title($postID) . '">' . get_the_title($postID) .'</a></span><br>';
  111.         echo '<span class="entry-meta">Dateline: <span itemprop="datePublished"> ' . $postDate . '</span> <span class="middot-large">&middot</span> ' . $postCityLink . ', ' . $postStateLink . '</span>';
  112.         //echo '<hr>';
  113.         echo ( wpautop (the_excerpt()) );
  114.         echo '</li>';
  115.         echo '</ul>';
  116.         endwhile;
  117.         if ( $count <> 0 ) {
  118.             echo '<p class="postlist-entry-meta">View all Stories in&nbsp;<a href="' . $term_link .'">' . $term->name . '</a>.&nbsp;&nbsp;<a href="' . $blogurl . '/add-your-story/">Share your <b>' . $term->name . '</b> story</a>!'; }
  119.     wp_reset_postdata();
  120.     }
  121.     echo '</div><!-- end itemscope -->';
  122. }
  123.  
  124. genesis();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement