[ create a new paste ] login | about

Link: http://codepad.org/Y7F7wTrf    [ raw code | fork ]

PHP, pasted on Dec 14:
<?php
//отображает 3 случайных товара
function show_rand_products()
{
?>
    <div class="product-listing">
        <div class="product-box">
            <?php
            $args = array( 'post_type' => 'product', 'posts_per_page' => 1, 'product_cat' => 'na-glavnuyu', 'orderby' => 'rand' );
            $loop = new WP_Query( $args );
            while ( $loop->have_posts() ) : $loop->the_post(); global $product; ?>
                <div class="item" onclick="location.href='<?php echo get_permalink( $loop->post->ID ) ?>'">
                    <?php if (has_post_thumbnail( $loop->post->ID )) echo get_the_post_thumbnail($loop->post->ID, 'shop_catalog'); else echo '<img src="'.woocommerce_placeholder_img_src().'" alt="Placeholder" width="790px" height="385px" />'; ?>
                    <div class="title-box">
                        <h3> <?php
                            $statevalues = get_the_terms( $product->id, 'pa_brends');
                            if(is_array($statevalues)) {
                                foreach ( $statevalues as $statevalue ) {
                                    echo $statevalue->name;}
                            }
                            ?></h3>
                        <span class="subtitle-text"><?php the_title(); ?></span>
                    </div>
                    <div class="hover-box">
                        <div class="box">
                            <a href="<?php echo get_permalink( $loop->post->ID ) ?>">подробнее</a>
                        </div>
                    </div>
                </div>
            <?php endwhile; ?>
            <?php wp_reset_query(); ?>
        </div>
        <div class="auxiliary-box">
            <div class="box">
                <img src="<?php echo get_template_directory_uri(); ?>/img/icon1.png" alt="image description" title="image description">
                <h3>мировые<br> бестселлеры</h3>
                <span class="subtitle-text">Признанные<br> и полюбившиеся</span>
            </div>
        </div>
    </div>
    <div class="product-listing alt">
        <div class="product-box">
            <?php
            $args = array( 'post_type' => 'product', 'posts_per_page' => 1, 'product_cat' => 'na-glavnuyu', 'orderby' => 'rand' );
            $loop = new WP_Query( $args );
            while ( $loop->have_posts() ) : $loop->the_post(); global $product; ?>
                <div class="item" onclick="location.href='<?php echo get_permalink( $loop->post->ID ) ?>'">
                    <?php if (has_post_thumbnail( $loop->post->ID )) echo get_the_post_thumbnail($loop->post->ID, 'shop_catalog'); else echo '<img src="'.woocommerce_placeholder_img_src().'" alt="Placeholder" width="790px" height="385px" />'; ?>
                    <div class="title-box">
                        <h3> <?php
                            $statevalues = get_the_terms( $product->id, 'pa_brends');
                            if(is_array($statevalues)) {
                                foreach ( $statevalues as $statevalue ) {
                                    echo $statevalue->name;}
                            }
                            ?></h3>
                        <span class="subtitle-text"><?php the_title(); ?></span>
                    </div>
                    <div class="hover-box">
                        <div class="box">
                            <a href="<?php echo get_permalink( $loop->post->ID ) ?>">подробнее</a>
                        </div>
                    </div>
                </div>
            <?php endwhile; ?>
            <?php wp_reset_query(); ?>
        </div>
        <div class="auxiliary-box">
            <div class="box">
                <img src="<?php echo get_template_directory_uri(); ?>/img/icon2.png" alt="image description" title="image description">
                <h3>скидочные<br> карты</h3>
                <span class="subtitle-text">Экономьте уже после<br> первой покупки</span>
            </div>
        </div>
    </div>
    <div class="product-listing">
        <div  class="product-box">
            <?php
            $args = array( 'post_type' => 'product', 'posts_per_page' => 1, 'product_cat' => 'na-glavnuyu', 'orderby' => 'rand' );
            $loop = new WP_Query( $args );
            while ( $loop->have_posts() ) : $loop->the_post(); global $product; ?>
                <div class="item" onclick="location.href='<?php echo get_permalink( $loop->post->ID ) ?>'">
                    <?php if (has_post_thumbnail( $loop->post->ID )) echo get_the_post_thumbnail($loop->post->ID, 'shop_catalog'); else echo '<img src="'.woocommerce_placeholder_img_src().'" alt="Placeholder" width="790px" height="385px" />'; ?>
                    <div class="title-box">
                        <h3> <?php
                            $statevalues = get_the_terms( $product->id, 'pa_brends');
                            if(is_array($statevalues)) {
                                foreach ( $statevalues as $statevalue ) {
                                    echo $statevalue->name;}
                            }
                            ?></h3>
                        <span class="subtitle-text"><?php the_title(); ?></span>
                    </div>
                    <div class="hover-box">
                        <div class="box">
                            <a href="<?php echo get_permalink( $loop->post->ID ) ?>">подробнее</a>
                        </div>
                    </div>
                </div>
            <?php endwhile; ?>
            <?php wp_reset_query(); ?>
        </div>
        <div class="auxiliary-box">
            <div class="box">
                <img src="<?php echo get_template_directory_uri(); ?>/img/icon3.png" alt="image description" title="image description">
                <h3>бесплатная<br> проверка зрения</h3>
                <span class="subtitle-text">Что бы очки подошли<br> вам идеально</span>
            </div>
        </div>
    </div>
<?php
}

if(isset($_GET['show_rand_products'])){show_rand_products(); exit;};


Output:
No errors or program output.


Create a new paste based on this one


Comments: