2015-05-29 53 views
0

我想显示所有woocommerce产品与链接上的woocommerce标题链接顶部帮助我的搜索引擎优化。我已经设法找到一些代码获取产品类别,但似乎无法让代码在链接上显示所有带有标题的产品。显示所有woocommerce产品喜欢与页脚标题搜索引擎优化 - WordPress的PHP

如果有人知道任何可以帮助我的代码,我将非常感谢所有带有链接和标题的产品!如果有更好的方法来获取数据比我使用,请让我知道!

<?php 
                  $taxonomy     = 'product_cat'; 
                  $orderby      = 'name';   
                  $show_count   = 0;      // 1 for yes, 0 for no 
                  $pad_counts   = 0;      // 1 for yes, 0 for no 
                  $hierarchical = 1;      // 1 for yes, 0 for no   
                  $title        = '';   
                  $empty        = 0; 
                $args = array(
                  'taxonomy'     => $taxonomy, 
                  'orderby'      => $orderby, 
                  'show_count'   => $show_count, 
                  'pad_counts'   => $pad_counts, 
                  'hierarchical' => $hierarchical, 
                  'title_li'     => $title, 
                  'hide_empty'   => $empty 
                ); 
                ?> 
                                 
                <?php $all_categories = get_categories($args); 
                //print_r($all_categories); 
                foreach ($all_categories as $cat) { 
                    //print_r($cat); 
                    if($cat->category_parent == 0) { 
                        $category_id = $cat->term_id; 
                ?>   
                                     
                <?php        
                 
                        echo '<a href="'. get_term_link($cat->slug, 'product_cat') .'">' . $cat->name .'</a>'; ?> | 
                 
                    <?php }      
                } 
                ?> 

回答

0

这是你想要的吗?

//you can remove post_status=>publish if you want unpublished product also 
$loop = new WP_Query(array('post_type' => 'product','post_status' => 'publish', 'posts_per_page' => '-1')); 

while ($loop->have_posts()) : $loop->the_post(); 
    echo "<a href='".get_post_permalink()."'>".$loop->post->post_title."</a><br>"; 
endwhile; 

EDITED

改变这样的查询:

$loop = new WP_Query(array('post_type' => 'product','post_status' => 'publish', 'posts_per_page' => '-1', 'orderby' => 'title', 'order' => 'ASC')); 
+0

这是完美的!非常感谢你!我现在正在试图按名称安排它,如果你知道有什么要做的话? – Daniel

相关问题