Php 在Wordpress中查看商业数据

Php 在Wordpress中查看商业数据,php,wordpress,woocommerce,Php,Wordpress,Woocommerce,我正在使用此代码尝试从woocommerce获取产品和类别 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 );

我正在使用此代码尝试从woocommerce获取产品和类别

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(); 

}
函数get\u me\u list\u of($atts,$content=null) { $args=array('post\u type'=>'product','post\u per\u page'=>10,'product\u cat'=>$atts[0],'orderby'=>'rand'); $loop=新的WP_查询($args); 回显“样式”。$atts[0]”; 回声“
    ”; 而($loop->have_posts()):$loop->the_post(); 全球$产品; 回音“
  • ”; 结束时; 回声“
”; wp_reset_query(); } 我把它放在一个文件中,并在使用的wordpress主题中将其命名为“template prods.php”。然后我创建了一个新页面,并使用了模板“prods”。但是页面上没有显示任何内容


代码是否有问题,或者是我试图查看数据的方式(即创建模板并在新页面中使用它)?

函数进入functions.php,然后在模板文件中访问这些函数。好的,但是我如何从模板调用函数?我是否只是简单地使用
I模板,它会显示在页面上?正确:)然后您可以在模板文件中使用您的函数