WordPress.org

Ready to get started?Download WordPress

Forums

WP eCommerce
wpsc_start_category_query loop problem (8 posts)

  1. lord_dev
    Member
    Posted 1 year ago #

    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/

  2. pixaque
    Member
    Posted 1 year ago #

    I do want same functionality. But I didn't find any solution anywhere. Please let me know if you have done it.

    Thank you.

  3. pixaque
    Member
    Posted 1 year ago #

    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/

    Thank you.
    pixaque

  4. lord_dev
    Member
    Posted 1 year ago #

    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

  5. pixaque
    Member
    Posted 1 year ago #

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

    Thank you.

  6. lord_dev
    Member
    Posted 1 year ago #

    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;
  7. yosukehasumi
    Member
    Posted 1 year ago #

    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(); ?>

  8. yosukehasumi
    Member
    Posted 1 year ago #

    <div class="category-count-<?php wpsc_print_category_count(); ?>">

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic