Created
March 21, 2011 20:04
-
-
Save sproutventure/880100 to your computer and use it in GitHub Desktop.
list of locations, link to latest deal instead of archive page
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function gb_list_locations_custom( $format = 'ul' ) | |
{ | |
global $gb; | |
// Form an array of all the locations ( the location term is called 'deals' ) | |
$locations = get_terms(array('deals'),array('hide_empty'=>true,'fields'=>'all')); | |
// Build out the ul of locations | |
if ( !empty( $locations) && $format == 'ul' ) { | |
echo "<ul class='locations-ul clearfix'>"; | |
foreach ($locations as $location) { | |
$args=array( | |
'post_type' => 'deal', | |
'post_status' => 'publish', | |
'deals' => $location->slug, | |
'meta_key' => $gb->_metaDealExpiration, | |
'posts_per_page' => 1 | |
); | |
$deal_query = new WP_Query($args); | |
if ($deal_query->have_posts()) { | |
while ($deal_query->have_posts()) : $deal_query->the_post(); | |
?> | |
<li id="location_slug_<?php echo $location->slug; ?>" class="location-item<?php if ( $location->name === gb_get_current_location() ) echo ' active'; ?>"> | |
<a href="<?php the_permalink(); ?>" title="Visit <?php echo $location->name; ?>'s Deals" id="locationslug-<?php echo $location->slug; ?>"><?php echo $location->name; ?></a> | |
</li> | |
<?php | |
endwhile; | |
} | |
} | |
echo "</ul>"; | |
} else { | |
foreach ($locations as $location) { | |
$link = get_term_link( $location->slug, 'deals'); | |
$args=array( | |
'post_type' => 'deal', | |
'post_status' => 'publish', | |
'deals' => $location->slug, | |
'meta_key' => $gb->_metaDealExpiration, | |
'posts_per_page' => 1 | |
); | |
$deal_query = new WP_Query($args); | |
if ($deal_query->have_posts()) { | |
while ($deal_query->have_posts()) : $deal_query->the_post(); | |
?> | |
<span id="location_slug_<?php echo $location->slug; ?>" class="location-item<?php if ( $location->name === gb_get_current_location() ) echo ' active'; ?>"> | |
<a href="<?php the_permalink(); ?>" title="Visit <?php echo $location->name; ?>'s Deals" id="locationslug-<?php echo $location->slug; ?>"><?php echo $location->name; ?></a> | |
</span> | |
<?php | |
endwhile; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment