Php 仅从父类别中获取选定的子类别
首先,我不是我朋友的开发者,我可以得到类别id为“1292”的所有子类别,但工作正常,但我只想显示我从类别“1292”中选择的部分类别Php 仅从父类别中获取选定的子类别,php,wordpress,Php,Wordpress,首先,我不是我朋友的开发者,我可以得到类别id为“1292”的所有子类别,但工作正常,但我只想显示我从类别“1292”中选择的部分类别 category id 1292有15个子类别,我希望其中一些可以从父id 1292逐页显示,如果有人知道相同的最佳方法,那么选择发生在哪里,您可以硬编码id以在代码中使用/跳过吗 您在$child中有孩子的术语id,只需添加 if(in_array($child, array(123, 456))) continue; 以前 $term = get_te
category id 1292有15个子类别,我希望其中一些可以从父id 1292逐页显示,如果有人知道相同的最佳方法,那么选择发生在哪里,您可以硬编码id以在代码中使用/跳过吗 您在$child中有孩子的术语id,只需添加
if(in_array($child, array(123, 456))) continue;
以前
$term = get_term_by( 'id', $child, $taxonomy_name );
要跳过类别123和456,或使用!在_array
中,仅显示这些,跳过其他。
当然,您可以使用变量来代替数组(123456)
编辑:将其转换为
add_shortcode( "mycategoryprinter" , function($attributes) {
$skipids = array();
if(array_key_exists("skipids", $attributes)) {
$skipids = preg_split("/\s*,\s*/", $attributes["skipids"]);
}
$term_id = $attributes["termid];
$taxonomy_name = $attributes["taxonomy];
// code goes here, change echo to return
});
然后你可以用它来做类似的事情
[mycategoryprinter termid="1292" taxonomy="product_cat" skipids="123, 456"][/mycategoryprinter]
你能解释一下在哪里添加代码或修改我发布的上面的代码吗,因为我从谷歌搜索中获得了这段代码用
foreach($child)替换foreach($child)替换{
withforeach($child)替换为“语法错误意外T_CONTINUE”哦,对不起,我的错误。在CONTINUE
之前,该行缺少一个结束语,我已编辑了我的答案。非常感谢您的帮助,但这项工作对我来说是“如果(!in_array($child,array(12971298)))继续;”刚刚添加了“!”因为我需要再次感谢您
[mycategoryprinter termid="1292" taxonomy="product_cat" skipids="123, 456"][/mycategoryprinter]