Jump to content


Photo

Php Code Shows Rows, Can I Change Amount Of Products Per Row?


  • Please log in to reply
3 replies to this topic

#1 jacko_162

jacko_162

    Advanced Member

  • Members
  • PipPipPip
  • 375 posts
  • LocationStaffordshire, United Kingdom

Posted 11 December 2012 - 07:36 PM

i have the following code;

<?php
/**
* Homepage Shop Panel
*/
 
/**
  * The Variables
  *
  * Setup default variables, overriding them if the "Theme Options" have been saved.
  */

global $woocommerce;

$settings = array(
	 'thumb_w' => 100,
	 'thumb_h' => 100,
	 'thumb_align' => 'alignleft',
	 'shop_area' => 'false',
	 'shop_area_entries' => 3,
	 'shop_area_title' => '',
	 'shop_area_message' => '',
	 'shop_area_link_text' => 'View all our products',
	 );
	
$settings = woo_get_dynamic_values( $settings );

?>
   <section id="shop-home" class="home-section fix">
	
	 
	   <ul class="recent products">
   
	 <?php
	 $number_of_products = $settings['shop_area_entries'];
	 $args = array( 'post_type' => 'product', 'posts_per_page' => $number_of_products, 'meta_query' => array( array('key' => '_visibility','value' => array('catalog', 'visible'),'compare' => 'IN')) );
	 $first_or_last = 'first';
	 $loop = new WP_Query( $args );
	 $count = 0;
	 global $post;
	 while ( $loop->have_posts() ) : $loop->the_post(); $_product = &new WC_Product( $loop->post->ID ); $count++; ?>
	
	  <li class="product <?php if ( $count % 3 == 0 ) { echo 'last'; } ?>">
	  
	   <a href="<?php echo get_permalink( $loop->post->ID ) ?>" title="<?php echo esc_attr($loop->post->post_title ? $loop->post->post_title : $loop->post->ID); ?>">
	  
	    <div class="img-wrap">
	   
		 <?php woocommerce_show_product_sale_flash( $post, $_product ); ?>
	   
		 <?php if (has_post_thumbnail( $loop->post->ID )) echo get_the_post_thumbnail($loop->post->ID, 'shop_thumbnail'); else echo '<img src="'.$woocommerce->plugin_url().'/assets/images/placeholder.png" alt="Placeholder" width="'.$woocommerce->get_image_size('shop_catalog_image_width').'px" height="'.$woocommerce->get_image_size('shop_catalog_image_height').'px" />'; ?>
	  
	    </div>
	  
	   </a>
	  
	   <h3><a href="<?php echo get_permalink( $loop->post->ID ) ?>" title="<?php echo esc_attr($loop->post->post_title ? $loop->post->post_title : $loop->post->ID); ?>"><?php the_title(); ?></a></h3>
	   
	   <span class="price"><?php echo $_product->get_price_html(); ?></span>
	    <?php woocommerce_template_loop_add_to_cart( $loop->post, $_product ); ?>
	   <div class="fix"></div>
	   
	  
	  </li>
	 
	  <?php if ( $count % 3 == 0 ) { echo '<li class="fix clear"></li>'; } ?>
	 <?php endwhile; ?>
   
    </ul><!--/ul.recent-->
	 
	  </section>
	 
	  <?php wp_reset_query(); ?>

upon loading it shows my latest products, it shows them in 3 columns then starts a new row with 3 columns and so on.

can i get it to show 4 or 5 products per row instead? if so what part do i need to understand and edit?

thanks
i love the phpfreaks :)

#2 Jessica

Jessica

    This is not my name.

  • Gurus
  • 8,982 posts
  • LocationDallas, TX
  • Age:26

Posted 11 December 2012 - 08:57 PM

Did you try looking for the number 3, and changing it to 4 or 5?
My goal in replying to posts is to help you become a better programmer, including learning how to debug your own code and research problems. For that reason, rather than posting the solution, I reply with tips and hints on how to find the solution yourself. See below for useful links when you get stuck.

How to Get Good Help: How to Ask Questions | Don't be a help vampire
Debugging Your Code: Debugging your SQL | What does a php function do? | What does a term mean? | Don't see any errors?
Things You Should Do: Normalize Your Data | use print_r() or var_dump()
Lulz: "Functions should not have side effects." - trq

Please take a look at my new PHP/Web Dev blog: The Web Mason - Thanks!!

#3 jacko_162

jacko_162

    Advanced Member

  • Members
  • PipPipPip
  • 375 posts
  • LocationStaffordshire, United Kingdom

Posted 11 December 2012 - 09:21 PM

Did you try looking for the number 3, and changing it to 4 or 5?


yes but no luck.
i love the phpfreaks :)

#4 jacko_162

jacko_162

    Advanced Member

  • Members
  • PipPipPip
  • 375 posts
  • LocationStaffordshire, United Kingdom

Posted 11 December 2012 - 09:29 PM

aaah something in css was stopping it showing correctly.

problem solved.
i love the phpfreaks :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com