2012-11-07 24 views
7

Sto utilizzando un tema già progettato per wordpress e ora invece dei normali post del blog vorrei visualizzare i prodotti WooCommerce (che sono tipi di post personalizzati che utilizzo). ciCreazione di un ciclo WooCommerce personalizzato

<?php 
       $args = array(
        //'posts_per_page' => '2', 
        'paged' => get_query_var('paged') 
       ); 
       $homepage_query = new WP_Query($args); 
      ?> 
      <?php //query_posts('posts_per_page=4&paged='.get_query_var('paged')); ?> 
      <?php if (have_posts()) : ?> 
       <?php while ($homepage_query->have_posts()) : $homepage_query->the_post(); ?> 
        <?php if($style == 'blog_style') { ?> 
        <div id="blog-style" class="post-box"> 
         <?php get_template_part('content', 'blog'); ?> 
        </div> 
        <?php } else { ?> 
        <div class="post-box grid_4 <?php aero_post_box_class(); ?>"> 
         <?php get_template_part('content', ''); ?> 
        </div> 
        <?php } ?> 
       <?php endwhile; ?> 

è un modo per aggiungere opzioni al $args così i prodotti di loop display WooCommerce:

Questa è la query corrente con il ciclo di visualizzazione? Sto anche usando la paginazione con questo ciclo, che è richiesto per questo progetto, ecco perché è importante usare questo ciclo.

risposta

22

Si dovrebbe essere in grado di accedere a prodotti attraverso il ciclo, l'impostazione del post_type arg a product:

<?php 

// Setup your custom query 
$args = array('post_type' => 'product', ...); 
$loop = new WP_Query($args); 

while ($loop->have_posts()) : $loop->the_post(); ?> 

    <a href="<?php echo get_permalink($loop->post->ID) ?>"> 
     <?php the_title(); ?> 
    </a> 

<?php endwhile; wp_reset_query(); // Remember to reset ?> 
+0

Sì, ora è in loop, fantastico! – jOpacic

+8

Se si desidera ottenere il prezzo, ecc. Si potrebbe voler fare: '$ product = get_product ($ loop-> post);' e quindi usarlo come 'WC_Product' è usato:' echo $ product-> get_price_html (); 'ecc. – Ciantic

0

è anche possibile ottenere Categoria usando Thi codice

 $terms = get_terms('product_cat'); 

     foreach ($terms as $term) { 
     $term_link = get_term_link($term, 'product_cat'); 
     echo '<li><a href="' . $term_link . '">' . $term->name . '</a></li>'; 
     } 

se desideri solo categoria padre poi

wp_list_categories('taxonomy=product_cat&orderby=order&title_li=&depth=1'); 
Problemi correlati