Wordpress 类别查询仅显示 4 个类别
Wordpress Category query to only show 4 categories
我试图在产品页面底部显示按 ID 排序的 4 个子类别
但是我不能让它只显示 4,它要么显示全部,要么 none?
$parent_id = 16;
$limit = 4;
$args = array(
'hierarchical' => 1,
'show_option_none' => '',
'posts_per_page' => $limit,
'orderby' => 'ID',
'hide_empty' => 0, // Set to 0 to show empty categories and 1 to hide them
'parent' => $parent_id,
'taxonomy' => 'product_cat'
);
$subcategories = get_categories($args);
foreach ($subcategories as $category) {
echo '<li><a href="'. $link .'">'.$category->name.'</a></li>';
}
如何让它只显示 4
谢谢
您需要在 $args 数组中使用 number
而不是 posts_per_page
。
我试图在产品页面底部显示按 ID 排序的 4 个子类别
但是我不能让它只显示 4,它要么显示全部,要么 none?
$parent_id = 16;
$limit = 4;
$args = array(
'hierarchical' => 1,
'show_option_none' => '',
'posts_per_page' => $limit,
'orderby' => 'ID',
'hide_empty' => 0, // Set to 0 to show empty categories and 1 to hide them
'parent' => $parent_id,
'taxonomy' => 'product_cat'
);
$subcategories = get_categories($args);
foreach ($subcategories as $category) {
echo '<li><a href="'. $link .'">'.$category->name.'</a></li>';
}
如何让它只显示 4
谢谢
您需要在 $args 数组中使用 number
而不是 posts_per_page
。