men*_*mam 3 filter categories woocommerce
我试着找到woo comm插件中的代码(短代码),它使得所有产品的列表来自一个类别,能够修改它... 1小时后没有运气,仍然没有找到.
所以我开始自己编码(重新发明轮子),在这里我试图获得
给我所有类别ID ="151"的产品,并能输出名称,永久链接等...
这是现在的代码,它返回所有内容....太多了!我不知道如何过滤它
{
$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;
}
Run Code Online (Sandbox Code Playgroud)
这是我找到的代码,并根据我的需要进行修改
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();
}
?>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
25008 次 |
| 最近记录: |