• Pretty simple what I am trying to do “Show 12 products per page with pagination on my home-template.php file”

    This is a loop I found online to try but it doesn’t work

    <ul class="products">
      <?php
        $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
        $args = array(
            'post_type' => 'product',
            'paged' => $paged,
            'posts_per_page' => 12
            );
        $loop = new WP_Query( $args );
        if ( $loop->have_posts() ) {
            while ( $loop->have_posts() ) : $loop->the_post();
                woocommerce_get_template_part( 'content', 'product' );
            endwhile;
        } else {
            echo __( 'No products found' );
        }
        wp_reset_postdata();
      ?>
    </ul>'
    
    Can your plugin even do this? I'm sure it can I just don't know how to do it. This seems pretty simple and straight forward which is why I'm irritated that I can't figure it out. :)
    
    

    ### WordPress Environment ###

    Home URL: https://www.americanfencestore.com
    Site URL: https://www.americanfencestore.com
    WC Version: 2.6.7
    Log Directory Writable: ?
    WP Version: 4.6.1
    WP Multisite: –
    WP Memory Limit: 256 MB
    WP Debug Mode: –
    WP Cron: ?
    Language: en_US

    ### Server Environment ###

    Server Info: Apache
    PHP Version: ? 5.4.45 – We recommend a minimum PHP version of 5.6. See: How to update your PHP version
    PHP Post Max Size: 64 MB
    PHP Time Limit: 30
    PHP Max Input Vars: 1000
    cURL Version: 7.19.7
    NSS/3.21 Basic ECC

    SUHOSIN Installed: –
    MySQL Version: ? 5.5.51 – We recommend a minimum MySQL version of 5.6. See: WordPress Requirements
    Max Upload Size: 64 MB
    Default Timezone is UTC: ?
    fsockopen/cURL: ?
    SoapClient: ?
    DOMDocument: ?
    GZip: ?
    Multibyte String: ?
    Remote Post: ?
    Remote Get: ?

    ### Database ###

    WC Database Version: 2.6.7
    :
    woocommerce_sessions: ?
    woocommerce_api_keys: ?
    woocommerce_attribute_taxonomies: ?
    woocommerce_downloadable_product_permissions: ?
    woocommerce_order_items: ?
    woocommerce_order_itemmeta: ?
    woocommerce_tax_rates: ?
    woocommerce_tax_rate_locations: ?
    woocommerce_shipping_zones: ?
    woocommerce_shipping_zone_locations: ?
    woocommerce_shipping_zone_methods: ?
    woocommerce_payment_tokens: ?
    woocommerce_payment_tokenmeta: ?
    MaxMind GeoIP Database: ?

    ### Active Plugins (15) ###

    Advanced Custom Fields PRO: by Elliot Condon – 5.4.8
    AG Custom Admin: by WAP – 5.6.5
    BackWPup: by Inpsyde GmbH – 3.3.4
    Contact Form 7: by Takayuki Miyoshi – 4.5.1
    Custom Post Type UI: by WebDevStudios – 1.4.3
    Product Enquiry for WooCommerce: by WisdmLabs – 1.4
    Shortcode Pagination for WooCommerce: by James Kemp – 1.0.5
    W3 Total Cache: by Frederick Townes – 0.9.5.1
    Woocommerce Login / Signup Lite: by phoeniixx – 1.4.1
    WooCommerce PDF & Print: by gVectors Team – 1.5.0
    WooCommerce Product Slider: by subhansanjaya – 1.2.1
    Woocommerce Products Per Page: by Jeroen Sormani – 1.2.2
    WooCommerce: by WooThemes – 2.6.7
    WordPress Importer: by wordpressdotorg – 0.6.3
    Yoast SEO: by Team Yoast – 3.8

    ### Settings ###

    Force SSL: –
    Currency: USD ($)
    Currency Position: left
    Thousand Separator: ,
    Decimal Separator: .
    Number of Decimals: 2

    ### API ###

    API Enabled: ?

    ### WC Pages ###

    Shop Base: #8 – /shop/
    Cart: #9 – /cart/
    Checkout: #10 – /checkout/
    My Account: #11 – /my-account/

    ### Taxonomies ###

    Product Types: external (external)
    grouped (grouped)
    simple (simple)
    variable (variable)

    ### Theme ###

    Name: JointsWP (Sass)
    Version: 2.0 (Sass)
    Author URL: https://www.yoururlhere.com
    Child Theme: ? – If you’re modifying WooCommerce on a parent theme you didn’t build personally
    then we recommend using a child theme. See: How to create a child theme

    WooCommerce Support: ? Not Declared

    ### Templates ###

    Overrides: Fencing/woocommerce/archive-product.php
    Fencing/woocommerce/content-product.php version 2.4.0 is out of date. The core version is 2.6.1
    Fencing/woocommerce/content-product_cat.php version 2.4.0 is out of date. The core version is 2.6.1
    Fencing/woocommerce/content-single-product.php
    Fencing/woocommerce/content-widget-product.php version – is out of date. The core version is 2.5.0
    Fencing/woocommerce/product-searchform.php version – is out of date. The core version is 2.5.0
    Fencing/woocommerce/single-product/add-to-cart/external.php
    Fencing/woocommerce/single-product/add-to-cart/grouped.php
    Fencing/woocommerce/single-product/add-to-cart/simple.php
    Fencing/woocommerce/single-product/add-to-cart/variable.php version 2.4.0 is out of date. The core version is 2.5.0
    Fencing/woocommerce/single-product/meta.php
    Fencing/woocommerce/single-product/price.php version 1.6.4 is out of date. The core version is 2.4.9
    Fencing/woocommerce/single-product/product-attributes.php
    Fencing/woocommerce/single-product/product-image.php version 2.0.14 is out of date. The core version is 2.6.3
    Fencing/woocommerce/single-product/product-thumbnails.php version 2.3.0 is out of date. The core version is 2.6.3
    Fencing/woocommerce/single-product/rating.php
    Fencing/woocommerce/single-product/related.php
    Fencing/woocommerce/single-product/review.php version 2.1.0 is out of date. The core version is 2.6.0
    Fencing/woocommerce/single-product/sale-flash.php
    Fencing/woocommerce/single-product/share.php
    Fencing/woocommerce/single-product/short-description.php
    Fencing/woocommerce/single-product/tabs/additional-information.php
    Fencing/woocommerce/single-product/tabs/description.php
    Fencing/woocommerce/single-product/tabs/tabs.php
    Fencing/woocommerce/single-product/title.php
    Fencing/woocommerce/single-product/up-sells.php
    Fencing/woocommerce/single-product-reviews.php
    Fencing/woocommerce/single-product.php
    Fencing/woocommerce/taxonomy-product_cat.php
    Fencing/woocommerce/taxonomy-product_tag.php

    : Learn how to update outdated templates
    `

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hello there,

    Try this code:

    
    <ul class="products">
      <?php
        $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    		var_dump($paged);
        $args = array(
            'post_type' => 'product',
            'paged' => $paged,
            'posts_per_page' => 3
            );
        $loop = new WP_Query( $args );
        if ( $loop->have_posts() ) {
            while ( $loop->have_posts() ) : $loop->the_post();
                woocommerce_get_template_part( 'content', 'product' );
            endwhile;
    
    				// Display numbered pagination
    				echo paginate_links( array(
    					'base'        => esc_url_raw( str_replace( 999999999, '%#%', remove_query_arg( 'add-to-cart', get_pagenum_link( 999999999, false ) ) ) ),
    					'format' 			=> '?paged=%#%',
    					'add_args'    => false,
    					'current' 		=> max( 1, get_query_var('paged') ),
    					'total' 			=> $loop->max_num_pages,
    					'prev_text'   => '&larr;',
    					'next_text'   => '&rarr;',
    					'type'        => 'list',
    					'end_size'    => 3,
    					'mid_size'    => 3
    				) );
    
        } else {
            echo __( 'No products found' );
        }
        wp_reset_postdata();
      ?>
    </ul>
    

    Refs:

    * WP codex
    * WC pagination template

    Thread Starter agon024

    (@agon024)

    Ya that works! Thanks. I still can’t believe this is so hard to do. The author should make this a lot easier.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Show products on home page w/pagination’ is closed to new replies.