WordPress.org

Ready to get started?Download WordPress

Forums

Random Products on Homepage (1 post)

  1. brainboxstudios
    Member
    Posted 10 months ago #

    Hey there,
    I'm working on this site at the moment and I have a selection of products on the homepage which need to be 'random' every time the page is refreshed. Currently it's just showing the most recent products uploaded from all categories.

    Could someone help me out? Here is the code for the home-products.php

    <?php $wp_query = new WP_Query(array('post_type'=>array('product'), 'product_cat'=>of_get_option('category_home'), 'posts_per_page'=>of_get_option('postnumber_home'))); ?>
    <?php if(is_tax()){ global $wp_query; $term = $wp_query->get_queried_object(); $title = $term->name; } ?>
    <?php if($wp_query->have_posts()) : ?>
    
    <?php if ( ! $title == '' ) { ?>
    	<?php if(of_get_option('display_cat_title') == '1') { ?>
    		<h3 class="headline-category text-center"><span><?php echo ($title); ?></span></h3>
    	<?php } ?>
    <?php } ?>
    
    <!-- BEGIN .products-container -->
    <ul class="products-container">
    
    	<?php while($wp_query->have_posts()) : $wp_query->the_post(); ?>
    	<?php global $more; $more = 0; ?>
    	<?php global $product; ?>
    
    	<!-- BEGIN .four columns -->
    	<li class="four columns">
    
    		<!-- BEGIN .product-holder -->
    		<div class="product-holder">
    
    			<?php if ( has_post_thumbnail()) { ?>
    			    <a class="feature-img" href="<?php the_permalink(); ?>" rel="bookmark" title="<?php echo esc_attr( sprintf( __( 'Permalink to %s', 'organicthemes' ), the_title_attribute( 'echo=0' ) ) ); ?>"><?php the_post_thumbnail( 'featured-small' ); ?></a>
    		    <?php } ?>
    
    		    <div class="information">
    
    			    <h2 class="title"><a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php echo esc_attr( sprintf( __( 'Permalink to %s', 'organicthemes' ), the_title_attribute( 'echo=0' ) ) ); ?>"><?php the_title(); ?></a></h2>
    
    			    <font color="#00ccff"><?php if ( $price_html = $product->get_price_html() ) : ?>
    			    	<div class="price"><?php echo $price_html; ?></div>
    			    <?php endif; ?>
    		    </font>
    		    </div>
    
    	   <!-- END .product-holder -->
    	   </div>
    
    	<!-- END .four columns -->
    	</li>
    
    	<?php endwhile; ?>
    
    <!-- END .products-container -->
    </ul>

    The site currently has a holding page up at the moment which is why I haven't included the URL.

    Thanks

Reply

You must log in to post.

About this Topic

  • RSS feed for this topic
  • Started 10 months ago by brainboxstudios
  • This topic is not resolved
  • WordPress version: 3.6