Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/255.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php WP电子商务。统计产品类别的数量_Php_Wordpress_E Commerce - Fatal编程技术网

Php WP电子商务。统计产品类别的数量

Php WP电子商务。统计产品类别的数量,php,wordpress,e-commerce,Php,Wordpress,E Commerce,我正在使用WP电子商务插件,目前正在尝试为产品类别构建一个站点地图页面 问题是,这些类别有很多,所以我想把它们分成两列 我从中得到了一段代码片段 从逻辑上看,它似乎会起作用,只是它在计算帖子而不是类别 显然,从下面的标记来看,我不确定我在做什么 <?php $catquery = wpsc_start_category_query( array( 'category_group' = >get_option('wpsc_default_category')

我正在使用WP电子商务插件,目前正在尝试为产品类别构建一个站点地图页面

问题是,这些类别有很多,所以我想把它们分成两列

我从中得到了一段代码片段

从逻辑上看,它似乎会起作用,只是它在计算帖子而不是类别

显然,从下面的标记来看,我不确定我在做什么

<?php 

$catquery = wpsc_start_category_query(
    array(
        'category_group' = >get_option('wpsc_default_category'), 
        'show_thumbnails'=> get_option('show_category_thumbnails')
    )
); 

$i = 0; 
if ($i == 0) echo '<div class="tri2"><ul>';
if ($i == (round($catquery->post_count / 2))) echo '</ul></div><div class="tri2"><ul>'; //this is where it probably fails 

?>
<li> 
    <a href="<?php wpsc_print_category_url();?>" class="wpsc_category_link <?php wpsc_print_category_classes_section(); ?>" title="<?php wpsc_print_category_name(); ?>">
        <?php wpsc_print_category_name(); ?>
    </a>

    <?php if(wpsc_show_category_description()) :?>
        <?php //wpsc_print_category_description("<div class='wpsc_subcategory'>", "</div>"); ?>
    <?php endif;?>

    <?php wpsc_print_subcategory("<ul>", "</ul>"); ?>
</li>

<?php 
if ($i == round($catquery->post_count)) echo '</ul></div>';;
$i++;
wpsc_end_category_query(); 
?>


  • 如果您所做的只是尝试获取产品类别的数量,那么只需使用WordPress函数()即可实现


    在任何情况下,我决定使用jQuery将类别列表分为两列。我希望用php实现这个结果。。
    <?php
        $list_args = array(
            'orderby' => 'name',
            'order' => 'ASC',
            'style' => 'list',
            'taxonomy' => 'product_cat',
            'show_count' => true,
            );
    
        $cat_array = get_categories($list_args);
    
        //This will be the number of categories.
        $category_count = 0;
    
        foreach($cat_array as $val){
            $category_count++;
        }
    
    ?>