Support » Plugin: WP eCommerce » 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!

Viewing 7 replies - 1 through 7 (of 7 total)
  • I do want same functionality. But I didn’t find any solution anywhere. Please let me know if you have done it.

    Thank you.


    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.

    Thank you.

    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?


    Yes you are correct I am also looking for this solution.

    Thank you.

    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) {
        	$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;

    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]',
    		$content_to_place = array(
    		esc_url( get_term_link( $category_row->slug, 'wpsc_product_category' ) ),

    Then you could just call it using something like:
    <?php wpsc_print_category_count(); ?>

    <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.