While loop containment not behaving.
Posted: Wed Aug 25, 2010 10:22 am
I have a while loop from a plugin, wp-ecommerce, which lists products on a page. What its currently doing is listing each item one after another. What I need to do is have 3 next to each other, identical to an older version of the website without this plugin.
However, when I put a table around it, it just doesn't really behave. The table can sit around one product at a time, or list them all in one continuous row. Which isn't really what I was after! I tried putting in a for loop ($i = 0; $i > 2; $i++) however this just manages to loop the whole set of products three times...
The code is exceptionately long but here it is:
And the link to the site is: the site.
I've currently taken my for loop out as it just doesnt work. Any hints or advice I could get at ordering this correctly?
Cheers,
Aravona
However, when I put a table around it, it just doesn't really behave. The table can sit around one product at a time, or list them all in one continuous row. Which isn't really what I was after! I tried putting in a for loop ($i = 0; $i > 2; $i++) however this just manages to loop the whole set of products three times...
The code is exceptionately long but here it is:
Code: Select all
<?php /** start the product loop here */?>
<br />
<img src="wp-content/plugins/wp-e-commerce/themes/default/images/bg_head.gif" />
<?php if(wpsc_category_transition()) :?>
<h3 class='wpsc_category_boundary'>
<?php echo wpsc_current_category_name(); ?>
</h3>
<?php endif; ?>
<table border="1">
<tr>
<?php while (wpsc_have_products()) : wpsc_the_product(); ?>
<td>
<div class="productdisplay default_product_display product_view_<?php echo wpsc_the_product_id(); ?> <?php echo wpsc_category_class(); ?>">
<div class="textcol">
<?php if(get_option('show_thumbnails')) :?>
<div class="imagecol">
<?php if(wpsc_the_product_thumbnail()) :?>
<a rel="<?php echo str_replace(array(" ", '"',"'", '"','''), array("_", "", "", "",''), wpsc_the_product_title()); ?>" class="thickbox preview_link" href="<?php echo wpsc_the_product_image(); ?>">
<img class="product_image" id="product_image_<?php echo wpsc_the_product_id(); ?>" alt="<?php echo wpsc_the_product_title(); ?>" title="<?php echo wpsc_the_product_title(); ?>" src="<?php echo wpsc_the_product_thumbnail(); ?>"/>
</a>
<?php else: ?>
<div class="item_no_image">
<a href="<?php echo wpsc_the_product_permalink(); ?>">
<span>No Image Available</span>
</a>
</div>
<?php endif; ?>
</div>
<?php endif; ?>
<div class="producttext">
<h2 class="prodtitles">
<?php if(get_option('hide_name_link') == 1) : ?>
<span><?php echo wpsc_the_product_title(); ?></span>
<?php else: ?>
<a class="wpsc_product_title" href="<?php echo wpsc_the_product_permalink(); ?>"><?php echo wpsc_the_product_title(); ?></a>
<?php endif; ?>
<?php echo wpsc_edit_the_product_link(); ?>
</h2>
<?php
do_action('wpsc_product_before_description', wpsc_the_product_id(), $wpsc_query->product);
do_action('wpsc_product_addons', wpsc_the_product_id());
?>
<div class='wpsc_description'><?php echo wpsc_the_product_description(); ?></div>
<?php if(wpsc_the_product_additional_description()) : ?>
<div class='additional_description_span'>
<a href='<?php echo wpsc_the_product_permalink(); ?>' class='additional_description_link'>
<img class='additional_description_button' src='<?php echo WPSC_URL; ?>/images/icon_window_expand.gif' title='Additional Description' alt='Additional Description' /><?php echo __('More Details', 'wpsc'); ?>
</a>
<div class='additional_description'>
<?php
$value = '';
$the_addl_desc = wpsc_the_product_additional_description();
if( is_serialized($the_addl_desc) ) {
$addl_descriptions = @unserialize($the_addl_desc);
} else {
$addl_descriptions = array('addl_desc'=> $the_addl_desc);
}
if( isset($addl_descriptions['addl_desc']) ) {
$value = $addl_descriptions['addl_desc'];
}
if( function_exists('wpsc_addl_desc_show') ) {
echo wpsc_addl_desc_show( $addl_descriptions );
} else {
echo stripslashes( wpautop($the_addl_desc, $br=1));
}
?>
</div>
<br />
</div>
<?php endif; ?>
<?php if(wpsc_product_external_link(wpsc_the_product_id()) != '') : ?>
<?php $action = wpsc_product_external_link(wpsc_the_product_id()); ?>
<?php else: ?>
<?php $action = htmlentities(wpsc_this_page_url(),ENT_QUOTES); ?>
<?php endif; ?>
<form class='product_form' enctype="multipart/form-data" action="<?php echo $action; ?>" method="post" name="product_<?php echo wpsc_the_product_id(); ?>" id="product_<?php echo wpsc_the_product_id(); ?>" >
<?php do_action('wpsc_product_addon_after_descr', wpsc_the_product_id()); ?>
<?php /** the custom meta HTML and loop */?>
<div class="custom_meta">
<?php while (wpsc_have_custom_meta()) : wpsc_the_custom_meta();
if (stripos(wpsc_custom_meta_name(),'g:') !== FALSE){
continue;
}
?>
<strong><?php echo wpsc_custom_meta_name(); ?>: </strong><?php echo wpsc_custom_meta_value(); ?><br />
<?php endwhile; ?>
</div>
<?php /** the custom meta HTML and loop ends here */?>
<?php /** add the comment link here */?>
<?php echo wpsc_product_comment_link(); ?>
<?php /** the variation group HTML and loop */?>
<div class="wpsc_variation_forms">
<?php while (wpsc_have_variation_groups()) : wpsc_the_variation_group(); ?>
<p>
<label for="<?php echo wpsc_vargrp_form_id(); ?>"><?php echo wpsc_the_vargrp_name(); ?>:</label>
<?php /** the variation HTML and loop */?>
<select class='wpsc_select_variation' name="variation[<?php echo wpsc_vargrp_id(); ?>]" id="<?php echo wpsc_vargrp_form_id(); ?>">
<?php while (wpsc_have_variations()) : wpsc_the_variation(); ?>
<option value="<?php echo wpsc_the_variation_id(); ?>" <?php echo wpsc_the_variation_out_of_stock(); ?> ><?php echo wpsc_the_variation_name(); ?></option>
<?php endwhile; ?>
</select>
</p>
<?php endwhile; ?>
</div>
<?php /** the variation group HTML and loop ends here */?>
<!-- THIS IS THE QUANTITY OPTION MUST BE ENABLED FROM ADMIN SETTINGS -->
<?php if(wpsc_has_multi_adding()): ?>
<label class='wpsc_quantity_update' for='wpsc_quantity_update[<?php echo wpsc_the_product_id(); ?>]'><?php echo __('Quantity', 'wpsc'); ?>:</label>
<input type="text" id='wpsc_quantity_update' name="wpsc_quantity_update[<?php echo wpsc_the_product_id(); ?>]" size="2" value="1"/>
<input type="hidden" name="key" value="<?php echo wpsc_the_cart_item_key(); ?>"/>
<input type="hidden" name="wpsc_update_quantity" value="true"/>
<?php endif ;?>
<p class="wpsc_extras_forms"/>
<div class="wpsc_product_price">
<?php if(wpsc_product_is_donation()) : ?>
<label for='donation_price_<?php echo wpsc_the_product_id(); ?>'><?php echo __('Donation', 'wpsc'); ?>:</label>
<input type='text' id='donation_price_<?php echo wpsc_the_product_id(); ?>' name='donation_price' value='<?php echo $wpsc_query->product['price']; ?>' size='6' />
<br />
<?php else : ?>
<?php if(wpsc_product_on_special()) : ?>
<span class='oldprice'><?php echo __('Price', 'wpsc'); ?>: <?php echo wpsc_product_normal_price(get_option('wpsc_hide_decimals')); ?></span><br />
<?php endif; ?>
<span id="product_price_<?php echo wpsc_the_product_id(); ?>" class="pricedisplay"><?php echo wpsc_the_product_price(get_option('wpsc_hide_decimals')); ?></span><?php echo __('Price', 'wpsc'); ?>: <br/>
<?php if(get_option('display_pnp') == 1) : ?>
<span class="pricedisplay"><?php echo wpsc_product_postage_and_packaging(get_option('wpsc_hide_decimals')); ?></span><?php echo __('P&P', 'wpsc'); ?>: <br />
<?php endif; ?>
<?php endif; ?>
</div>
<input type="hidden" value="add_to_cart" name="wpsc_ajax_action"/>
<input type="hidden" value="<?php echo wpsc_the_product_id(); ?>" name="product_id"/>
<!-- END OF QUANTITY OPTION -->
<?php if((get_option('hide_addtocart_button') == 0) && (get_option('addtocart_or_buynow') !='1')) : ?>
<?php if(wpsc_product_has_stock()) : ?>
<div class='wpsc_buy_button_container'>
<?php if(wpsc_product_external_link(wpsc_the_product_id()) != '') : ?>
<?php $action = wpsc_product_external_link(wpsc_the_product_id()); ?>
<input class="wpsc_buy_button" type='button' value='<?php echo __('Buy Now', 'wpsc'); ?>' onclick='gotoexternallink("<?php echo $action; ?>")'>
<?php else: ?>
<input type="submit" value="<?php echo __('Add To Cart', 'wpsc'); ?>" name="Buy" class="wpsc_buy_button" id="product_<?php echo wpsc_the_product_id(); ?>_submit_button"/>
<?php endif; ?>
<div class='wpsc_loading_animation'>
<img title="Loading" alt="Loading" src="<?php echo WPSC_URL; ?>/images/indicator.gif" class="loadingimage"/>
<?php echo __('Updating cart...', 'wpsc'); ?>
</div>
</div>
<?php else : ?>
<p class='soldout'><?php echo __('This product has sold out.', 'wpsc'); ?></p>
<?php endif ; ?>
<?php endif ; ?>
</form>
<?php if((get_option('hide_addtocart_button') == 0) && (get_option('addtocart_or_buynow')=='1')) : ?>
<?php echo wpsc_buy_now_button(wpsc_the_product_id()); ?>
<?php endif ; ?>
<?php echo wpsc_product_rater(); ?>
<?php
if(function_exists('gold_shpcrt_display_gallery')) :
echo gold_shpcrt_display_gallery(wpsc_the_product_id(), true);
endif;
?>
</div>
</div>
</div>
</td>
<?php endwhile; ?>
</tr>
</table>
<?php /** end the product loop here */?>I've currently taken my for loop out as it just doesnt work. Any hints or advice I could get at ordering this correctly?
Cheers,
Aravona