Advertisement
Guest User

Wordpress display list of posts according to custom taxonomy

a guest
Sep 11th, 2012
354
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.12 KB | None | 0 0
  1. <?php while ( have_posts() ) : the_post(); ?>
  2.     <?php if (is_page(171)) {  //create variables for the venue type
  3.         $venueType = 'event-venue';
  4.     } else {
  5.         $venueType = 'reception-venue';
  6.     } ?>
  7.     <?php get_template_part( 'content', 'page' ); ?>
  8.  
  9.     <?php
  10.         $post_type = 'venues';
  11.         $tax = 'venue-city';
  12.         $tax_terms = get_terms($tax,'hide_empty=0');
  13.        
  14.        
  15.         if (is_page(12) || is_page(171)) {
  16.         //list everything
  17.         if ($tax_terms) {
  18.           foreach ($tax_terms  as $tax_term) {
  19.             $args=array(
  20.               'post_type' => $post_type,
  21.               'venue-type' => $venueType, //test to see if we can add another dimension
  22.               "$tax" => $tax_term->slug,
  23.               'post_status' => 'publish',
  24.               'posts_per_page' => -1,
  25.               'caller_get_posts'=> 1
  26.             );
  27.        
  28.             $my_query = null;
  29.             $my_query = new WP_Query($args);
  30.             if( $my_query->have_posts() ) {
  31.               echo "<h2 class=\"category-title\" > $tax_term->name </h2><ul class=\"page-listing\">";
  32.               while ($my_query->have_posts()) : $my_query->the_post(); ?>
  33.                 <li><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></li>
  34.                 <?php
  35.               endwhile;
  36.              
  37.              
  38.             }echo "</ul>";
  39.             wp_reset_query();
  40.           }
  41.         }
  42.         } else {
  43.        
  44.         //list everything
  45.         if ($tax_terms) {
  46.           foreach ($tax_terms  as $tax_term) {
  47.             $args=array(
  48.               'post_type' => $post_type,
  49.               //'venue-type' => 'event-venue', //test to see if we can add another dimension
  50.               "$tax" => $tax_term->slug,
  51.               'post_status' => 'publish',
  52.               'posts_per_page' => -1,
  53.               'caller_get_posts'=> 1
  54.             );
  55.        
  56.             $my_query = null;
  57.             $my_query = new WP_Query($args);
  58.             if( $my_query->have_posts() ) {
  59.               echo "<h2 class=\"category-title\" > $tax_term->name </h2><ul class=\"page-listing\">";
  60.               while ($my_query->have_posts()) : $my_query->the_post(); ?>
  61.                 <li><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></li>
  62.                 <?php
  63.               endwhile;
  64.              
  65.              
  66.             }echo "</ul>";
  67.             wp_reset_query();
  68.           }
  69.         }}
  70.         ?>
  71.     <?php endwhile; // end of the loop. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement