[wp-hackers] Looping through categories

Ryan Bilesky rbilesky at gmail.com
Tue Oct 26 04:29:57 UTC 2010


Well not sure if this absolutely the best way to do this but what I would do
is this

have a for each loop to go though categories, inside that set a Boolean to
false then do a for each with the posts that are in that category, check the
meta data and if it matches what you need set the Boolean true and exit that
loop then you can build add to the output if the Boolean is set to true.

On Mon, Oct 25, 2010 at 5:37 PM, Brian Fidler <fidler.brian at gmail.com>wrote:

> 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
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>


More information about the wp-hackers mailing list