• Hi,
    I need help. Me wrote query in my wordpress theme to fetch latest products. Everything is working perfect. But don’t know why pagination not working. I did select 9 post in backend. it’s appear 9 on my home page. But i want to show all products on homepage with pagination.

    Here is my homepage url : https://galexymobile.com/chipman/

    But if you see in category page https://galexymobile.com/chipman/?product_cat=musicians pagination working fine.

    Here is my homepage code.

    Pliz let me know where is the problem:

    <div class="products">
                	<?php
    
    // Setup your custom query
    $args = array( 'post_type' => 'product', );
    $loop = new WP_Query( $args );
    
    while ( $loop->have_posts() ) : $loop->the_post(); ?>
    <div class="pro-item">
    
    <div class="pro-item-title"><a>post->ID ) ?>"><?php the_title(); ?></a></div>
    <div class="pro-item-content">
    
    <div class="pro-item-image">    <a>post->ID ) ?>">
            <?php
    		if(has_post_thumbnail()) {
    					the_post_thumbnail($size);
    				}
    			?>
    			<?php
    				global $more;
    				$more = 0;
    			?>
        </a></div><div class="pro-item-desc"><?php the_content(); ?>Price : $<?php echo get_post_meta($post->ID, "_regular_price", $single = true); ?></div><div class="pro-item-btn">
        <?php
    
    do_action( 'woocommerce_after_shop_loop_item' ); ?>
        </div>
    
    </div></div>
    <?php endwhile; wp_pagenavi(); // Remember to reset ?>
    
                </div>

    Can anyone recode and replace his code again. I really need this.

Viewing 1 replies (of 1 total)
  • Please check below url:
    [Link moderated]

    or you can follow below code

    Please first install “WP-Pagenavi” plugin to your store.

    and then write below code to your home page template.

    <?php
    
    global $paged;
    if( get_query_var( 'paged' ) )
    $my_page = get_query_var( 'paged' );
    else {
    if( get_query_var( 'page' ) )
    $my_page = get_query_var( 'page' );
    else
    $my_page = 1;
    set_query_var( 'paged', $my_page );
    $paged = $my_page;
    }
    $args = array( 'post_type' => 'product', 'paged' => $my_page, 'posts_per_page' => 8 );
    $loop = new WP_Query( $args );
    
    echo '
    <ul>';
    while ( $loop->have_posts() ) : $loop->the_post();
    
    	echo '<li class="product">';
    			echo '<a>ID ) ).'" title="'.esc_attr($post->post_title ? $post->post_title : $post->ID).'">';
    			if ( has_post_thumbnail($post->ID) ) {
    				echo get_the_post_thumbnail( $post->ID, apply_filters( 'single_product_large_thumbnail_size', 'shop_single' ) );
    			} else {
    				echo apply_filters( 'woocommerce_single_product_image_html', sprintf( '<img src="%s" alt="Placeholder" />', woocommerce_placeholder_img_src() ), $post->ID );
    			}
    			echo '</a>';
    			if(get_post_meta( $post->ID, '_regular_price', true) != ''){
    				echo '<span class="price"><span class="amount">$'.number_format(get_post_meta( $post->ID, '_regular_price', true), 2, '.', '').'</span></span>';
    			} else {
    				echo '<span class="price"><span class="amount">?</span></span>';
    			}
    			echo '<p>'.substr(strip_tags($post->post_content),0,25).'...</p>';
    			echo '<div class="info"><a href="'.get_permalink().'">INFO</a></div>';
    
    	echo '';
    endwhile;
    wp_pagenavi(array( 'query' => $loop ));
    wp_reset_query();
    ?></ul>

    [Moderator Note: Please post code & markup between backticks or use the code button. Your posted code has now been permanently damaged by the forum’s parser.]

Viewing 1 replies (of 1 total)
  • The topic ‘Woocommerce Products show on homepage with pagination.’ is closed to new replies.