Title: wpsc_start_category_query loop problem
Last modified: August 20, 2016

---

# wpsc_start_category_query loop problem

 *  [lord_dev](https://wordpress.org/support/users/lord_dev/)
 * (@lord_dev)
 * [13 years, 5 months ago](https://wordpress.org/support/topic/wpsc_start_category_query-loop-problem/)
 * Hey
 * I am looping wpsc_start_category_query on the homepage of my website so that 
   I can show all the categories in my store. This works fine.
 * However, I cannot assign logic or numbers to each individual category being dispaly.
   For example, I would like every fourth image to be assigned with ‘class=”last-
   cateogry”‘ so I can set unique margins for the last category in the column.
 * You can usually do this by using a simple conditional statements:
 * `<?php if($i == 4){div class='last-category'>CONTENT HERE</div>} ?>`
 * However, this does not work (I presume being its not wrapped in a for each or
   while loop).
 * Any help appreciated, thanks!
 * [http://wordpress.org/extend/plugins/wp-e-commerce/](http://wordpress.org/extend/plugins/wp-e-commerce/)

Viewing 7 replies - 1 through 7 (of 7 total)

 *  [pixaque](https://wordpress.org/support/users/pixaque/)
 * (@pixaque)
 * [13 years, 5 months ago](https://wordpress.org/support/topic/wpsc_start_category_query-loop-problem/#post-3288304)
 * I do want same functionality. But I didn’t find any solution anywhere. Please
   let me know if you have done it.
 * Thank you.
 *  [pixaque](https://wordpress.org/support/users/pixaque/)
 * (@pixaque)
 * [13 years, 5 months ago](https://wordpress.org/support/topic/wpsc_start_category_query-loop-problem/#post-3288305)
 * lord_dev,
 * I found this code may be help full to you.
 * <?php wpsc_start_category_query(array(‘category_group’=> get_option(‘wpsc_default_category’),‘
   show_thumbnails’=> 1)); ?>
    ” class=”wpsc_category_grid_item <?php wpsc_print_category_classes_section();?
   >” title=”<?php wpsc_print_category_name(); ?>”> <?php wpsc_print_category_image(
   get_option(‘category_image_width’),get_option(‘category_image_height’)); ?>  
   <?php wpsc_print_subcategory(“”, “”); ?> <?php wpsc_end_category_query(); ?>
 * you can find it here.
 * [http://docs.getshopped.org/documentation/wpsc_end_category_query/](http://docs.getshopped.org/documentation/wpsc_end_category_query/)
 * Thank you.
    pixaque
 *  Thread Starter [lord_dev](https://wordpress.org/support/users/lord_dev/)
 * (@lord_dev)
 * [13 years, 5 months ago](https://wordpress.org/support/topic/wpsc_start_category_query-loop-problem/#post-3288306)
 * Hi Pixaque,
 * Thanks for the input.
 * Unfortunately wpsc_print_category_classes_section(); does not print anything (
   maybe this is a bug?) Even if it did work, I doubt its much use – if my client
   deletes a category or moves the order then the styling will be irrelevant.
 * I have something slightly helpful – wpsc_print_category_id() – this just prints
   the category ID so you can style classes uniquely. However, same problem – if
   my client deletes or moves the order of the categories then this functionality
   is pointless.
 * I would really like a proper indexed solution. Does anyone know how to display
   all the Categories with a For Each or While loop?
 * Thanks
 *  [pixaque](https://wordpress.org/support/users/pixaque/)
 * (@pixaque)
 * [13 years, 5 months ago](https://wordpress.org/support/topic/wpsc_start_category_query-loop-problem/#post-3288307)
 * Yes you are correct I am also looking for this solution.
 * Thank you.
 *  Thread Starter [lord_dev](https://wordpress.org/support/users/lord_dev/)
 * (@lord_dev)
 * [13 years, 5 months ago](https://wordpress.org/support/topic/wpsc_start_category_query-loop-problem/#post-3288311)
 * UPDATE: I’ve found a way of looping the Categories by using the get_terms() function.
   Unfortunately I can only get the Category Titles to loop. Anyone have any idea
   how to get images and links via a get_terms loop?
 *     ```
       $terms = get_terms("wpsc_product_category","hide_empty=0&parent=0", OBJECT, "display")
   
           foreach ($terms as $term) {
               $i++;
           	$term_list .= '<a href="/term-base/' . $term->slug . '" title="' . sprintf(__('View all post filed under %s', 'my_localization_domain'), $term->name) . '">' . $term->name . '</a>';
           	if ($count != $i) $term_list .= ' &middot; '; else $term_list .= '</p>';
           }
           echo $term_list;
       ```
   
 *  [yosukehasumi](https://wordpress.org/support/users/yosukehasumi/)
 * (@yosukehasumi)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/wpsc_start_category_query-loop-problem/#post-3288344)
 * bump, I’d be interested in this also. I’ve been poking around the category.functions.
   php file and I can see the reason that we’re not able to use any kind of simple
   variable is because the function does a single DB call and outputs all of the
   HTML by the time it even gets into our hands… Simply speaking this isn’t a loop
   at all, just a very elaborate database query.
 * I’ve been able to bring out a post count in plain HTML but for my application
   I need to figure out how to get a PHP variable in my hands so that I can split
   my output into two sections a TOP and BOTTOM output (if that makes sense).
 * If your simply looking for an HTML output you can create a new function in “wpsc-
   includes/category.functions.php”:
 *     ```
       /**
       * wpsc print category count function
       * places the shortcode for the category count
       */
       function wpsc_print_category_count(){
       	echo "[wpsc_print_category_count]";
       }
       ```
   
 * On line 266-ish add a key to the foreach:
    `foreach((array)$category_data as 
   $count => $category_row) {`
 * Add the shortcode and replacement value into the output on line 362-ish:
 *     ```
       // get the list of products associated with this category.
       		$tags_to_replace = array('[wpsc_category_name]',
       		'[wpsc_category_description]',
       		'[wpsc_category_url]',
       		'[wpsc_category_id]',
       		'[wpsc_category_classes]',
       		'[wpsc_category_image]',
       		'[wpsc_subcategory]',
       		'[wpsc_category_products_count]',
       		'[wpsc_print_category_count]');
   
       		$content_to_place = array(
       		esc_html($category_row->name),
       		$category_description,
       		esc_url( get_term_link( $category_row->slug, 'wpsc_product_category' ) ),
       		$category_row->term_id,
       		$category_classes,
       		$category_image_html,
       		$sub_categories,
       		$category_count_html,
       		$count);
       ```
   
 * Then you could just call it using something like:
    `<?php wpsc_print_category_count();?
   >`
 *  [yosukehasumi](https://wordpress.org/support/users/yosukehasumi/)
 * (@yosukehasumi)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/wpsc_start_category_query-loop-problem/#post-3288345)
 * `<div class="category-count-<?php wpsc_print_category_count(); ?>">`

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘wpsc_start_category_query loop problem’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/wp-e-commerce_ebebeb.svg)
 * [WP eCommerce](https://wordpress.org/plugins/wp-e-commerce/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-e-commerce/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-e-commerce/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-e-commerce/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-e-commerce/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-e-commerce/reviews/)

## Tags

 * [loop](https://wordpress.org/support/topic-tag/loop/)
 * [problem](https://wordpress.org/support/topic-tag/problem/)
 * [wp ecommerce](https://wordpress.org/support/topic-tag/wp-ecommerce/)

 * 7 replies
 * 3 participants
 * Last reply from: [yosukehasumi](https://wordpress.org/support/users/yosukehasumi/)
 * Last activity: [13 years, 3 months ago](https://wordpress.org/support/topic/wpsc_start_category_query-loop-problem/#post-3288345)
 * Status: not resolved