WooCommerce Custom Loop从一个特定类别获取所有产品 [英] WooCommerce Custom Loop to get all product from one specific category

查看:287
本文介绍了WooCommerce Custom Loop从一个特定类别获取所有产品的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在woo comm插件中找到代码(短代码),将所有产品的列表从一个类别中删除,以便能够对其进行修改... 1小时后没有运气,仍然没有发现。 / p>

所以我开始编码它自己(重新发明轮子),在这里我试图得到



让我所有产品从类别ID =151,并能够输出名称,永久链接等等等等。

这是现在的代码,返回所有内容。 ..太多了!我不知道怎么过滤它
$ b $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $'$'$''$ '=>'product',
'posts_per_page'=> 99
);

$ loop = new WP_Query($ args);
if($ loop-> have_posts()){
while($ loop-> have_posts()):$ loop-> the_post();
// echo get_title()。< br />;
var_dump($ loop);
endwhile;


解决方案

找到并修改我的需求
$ b $ pre $ $ $ $ $ $ $ $ $ $ $ $ $ $ b $ args = array('post_type'=>'product','posts_per_page'=> 10,'product_cat'=> $ atts [0],'orderby'=>'rand');

$ loop = new WP_Query($ args);

echo'< h1 class =upp> Style'。$ atts [0]。'< / h1>';
echo< ul class ='mylisting'>;
while($ loop-> have_posts()):$ loop-> the_post();
global $ product;
$ b $ echo'< li>< a href ='。get_permalink()。'>'get_the_post_thumbnail($ loop-> post-> ID,'thumbnail')。 '< / A>< /立GT;';

endwhile;

echo< / ul>;

wp_reset_query();

}

?>


I try to find the code (short code) in the woo comm plugin that made the list of all the product from one category, to be able to modify it... no luck after 1 hours, still no find.

So i start coding it myself (reinventing the wheel) and here what i try to get

get me all the product from category ID="151" and be able to output the name, the permalink etc etc...

this is the code now, that return everything.... way too much ! and i don't know how to filter it

{
$args = array(
    'post_type' => 'product',
    'posts_per_page' => 99
);

$loop = new WP_Query( $args );
if ( $loop->have_posts() ) {
while ( $loop->have_posts() ) : $loop->the_post();
    //echo get_title()."<br/>";
    var_dump($loop);
endwhile;
} 

解决方案

here is the code i have found, and modify to my needs

function get_me_list_of($atts, $content = null)
{   
    $args = array( 'post_type' => 'product', 'posts_per_page' => 10, 'product_cat' => $atts[0], 'orderby' => 'rand' );

    $loop = new WP_Query( $args );

    echo '<h1 class="upp">Style '.$atts[0].'</h1>';
    echo "<ul class='mylisting'>";
    while ( $loop->have_posts() ) : $loop->the_post(); 
    global $product; 

    echo '<li><a href="'.get_permalink().'">'.get_the_post_thumbnail($loop->post->ID, 'thumbnail').'</a></li>';

    endwhile; 

    echo "</ul>";

    wp_reset_query(); 

}

?>

这篇关于WooCommerce Custom Loop从一个特定类别获取所有产品的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆