[wp-hackers] Looping through categories

Brian Fidler fidler.brian at gmail.com
Tue Oct 26 00:37:41 UTC 2010


I need to loop through my categories however I need to limit the categories
to those categories that include posts where the custom field of price != 0
or null.

What is the best way to handle this?

Currently I've got this...

<div id="page-categories" style="margin-top:-34px;">

<!-- PRINT CATEGORY LISTINGS -->
<?php

$categories=get_categories();
foreach($categories as $category) {

?>

<?php
$myColumnCount = 1;
?>

<h2 style="clear:both;"><a href="<?php bloginfo('url'); ?>/category/<?php
echo($category->slug); ?>"><?php echo($category->name); ?></a></h2>

<?php
query_posts('cat='.$category->cat_ID.'&posts_per_page=-1&orderby=title&order=ASC');
?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>

<!-- YOUR POST DISPLAYING CODE GOES HERE -->

<div id="" class="span-1 <?php if ($myColumnCount==6) { echo "last"; } ?>
thumb20" >
<a class="thumb" href="<?php the_permalink(); ?>" rel="bookmark" title="Link
to <?php the_title(); ?>" >
<?php echo the_post_thumbnail( 'thumbnail' ); ?>
</a>
</div>
<!-- YOUR POST DISPLAYING CODE GOES HERE -->

<?php if ($myColumnCount == 6) {
$myColumnCount=0;
} ?>

<?php $myColumnCount = $myColumnCount+1; ?>

<?php
 endwhile;
endif;
echo '<hr class="gallery-grid" />';
?>
<?php } ?>

<?php $wp_query = $temp_query; ?>
</div>

 [image: brian fidler interactive] <http://www.brianfidler.com>
[image: Follow brianfidler on twitter] <http://www.twitter.com/brianfidler>
 [image: View Brian Fidler's profile on
LinkedIn]<http://www.linkedin.com/in/brianfidler>
 [image: Join brian fidler interactive on
facebook]<http://www.facebook.com/BrianFidlerInteractive>
 email: interactive at brianfidler.com
phone: 602.758.4733


More information about the wp-hackers mailing list