【问题标题】:how to set category list limit?如何设置类别列表限制?
【发布时间】:2014-10-17 10:47:09
【问题描述】:

我正在显示帖子类别子列表。列表显示全部 我只需要显示 6 个(孩子) 帮助我们...

例如: 菜单(父) list1(儿童) list2(儿童) 清单 3(儿童) list4(儿童) 清单 5(儿童) 清单 6(儿童) 清单 7(儿童) list8(儿童)

<?php $article_categories = get_categories(array(
                                    'child_of' => get_category_by_slug('work')->term_id
                            ));
    $talentChildren = get_categories(array('child_of' => get_category_by_slug('talent')->term_id));


 ?>
    <?php if ( have_posts()) : ?>
        <?php $talent_Children = array($talentChildren[0]); ?>
        <?php foreach($talent_Children as $talent): ?>
        <?php
        $talentSubChildren = new WP_Query();
        $talentSubChildren->query(array('category_name' => $talent->slug));
        ?>
        <h2><a href="<?php the_permalink() ?>talent/directors/"><?php echo $talent->name; ?></a></h2>
        <ul>
        <?php while ($talentSubChildren->have_posts()) : $talentSubChildren->the_post(); ?>
        <li>
        <h4><a href="<?php the_permalink() ?>"><?php the_title(); ?></a>
        </h4>
        </li>
        <?php endwhile; ?>
        </ul>
        <?php endforeach; ?>
        <?php endif; ?>
        </div>

【问题讨论】:

    标签: php wordpress wordpress-theming


    【解决方案1】:

    你可以在 get_categories 函数中使用 user number =6

    $talentChildren = get_categories(array('child_of' => get_category_by_slug('news')->term_id,'number' => 6,'hide_empty' => 0));
    foreach($talentChildren as $talent):
        echo "<pre>";
        print_r($talent);
        echo "</pre>";
    endforeach;
    

    【讨论】:

    • 我收到 -> 语法错误,意外 '=>' (T_DOUBLE_ARROW) 如何解决此错误
    • 你试过了吗?工作了吗?
    • stdClass 对象([term_id] => 23 [name] => Director [slug] => director [term_group] => 0 [term_taxonomy_id] => 24 [taxonomy] => category [description] => [parent] => 15 [count] => 6 [cat_ID] => 23 [category_count] => 6 [category_description] => [cat_name] => 导演 [category_nicename] => 导演 [category_parent] => 15)
    • 它工作正常和另一个帮助。现在显示 [slug] => 导演 [count] => 显示 6。我只需要显示 2.帮助我们
    • 你可以将数字改为2
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-02-27
    • 1970-01-01
    • 2021-01-14
    • 1970-01-01
    • 1970-01-01
    • 2020-10-12
    • 2011-06-14
    相关资源
    最近更新 更多