• Resolved pradeeppl

    (@pradeeppl)


    I need it for Particular Category Product Posts. Title of the Product Post and Product Image.

    <?php
        $SelectedPosts = new WP_Query('cat=4&showposts=6');
        if($SelectedPosts->have_posts()):
        while($SelectedPosts->have_posts()) : $SelectedPosts->the_post();
    ?>
    <ul class="home_posts">
        <li>
        <?php
            if ( has_post_thumbnail() ) {
            the_post_thumbnail('home_posts');
            } else {
        ?>
            <img class="home_image" src="<?php bloginfo('template_directory'); ?>/images/placeholder.png" alt="<?php the_title(); ?>" />
        <?php } ?>
            <div class="overlay">
                <h3><?php the_title();?></h3>
                <a class="info" href="<?php the_permalink(); ?>">View Details</a>
            </div>
            <span><?php the_title();?></span><br />
            <span>Rs.750/-</span>
        </li>
    </ul>
    <?php
        endwhile;
        else :
    ?>
        <p>No Updates</p>
    <?php
        endif;
    ?>
Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Mike Jolley (a11n)

    (@mikejolley)

    Use wc_get_product() function to get a product object, then use $product->get_image() and $product->get_title() to get that data.

    Thread Starter pradeeppl

    (@pradeeppl)

    Thanks!! got solution for it!

    <?php
                        $args = array( 'post_type' => 'product', 'stock' => 1, 'posts_per_page' => 6, 'product_cat' => 'ACE', 'orderby' =>'rand','order' => 'DESC' );
                        $loop = new WP_Query( $args );
                        if($loop->have_posts()):
                        while($loop->have_posts()) : $loop->the_post();  global $product;
                    ?>
                    <ul class="home_posts">
                        <li>
                            <?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="300px" height="300px" />'; ?>
                                <div class="overlay">
                                    <h3><?php the_title();?></h3>
                                    <a class="info" href="<?php the_permalink(); ?>">View Details</a>
                                </div>
                            <span><?php the_title();?></span><br />
                            <span><?php echo $product->get_price_html(); ?>/-</span>
                        </li>
                    </ul>
                    <?php
                        endwhile;
                        else :
                    ?>
                    <p>No Updates</p>
                    <?php
                        endif;
                    ?>
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Category wise Latest Product Posts for Home Page’ is closed to new replies.