在我们开发WordPress主题的过程中,如果有一个需求是要获取到父分类的所有子分类,该怎么实现呢?
其实这个需求是很简单的,几行代码就可以搞定。
今天路途吧给大家带来一个小小的wordpress教程,如何在父分类获取所有子分类/二级分类。
首先在function.php里面添加下面的代码。
//父分类获取所有子分类
function get_category_root_id($cat) {
$this_category = get_category($cat); // 取得当前分类
while($this_category->category_parent) // 若当前分类有上级分类时,循环
{
$this_category = get_category($this_category->category_parent); // 将当前分类设为上级分类往上爬
}
return $this_category->term_id; // 返回根分类的id号
}
使用方法
将下面代码放在需要用到子分类的父分类即可
<?php wp_list_categories(
$args = array(
\'show_option_all\' => \'\',
\'orderby\' => \'name\',
\'use_desc_for_title\' => 1,
\'child_of\' => get_category_root_id($cat),
\'optioncount\'=>1,
\'hierarchical\' => 1,
\'title_li\' => \'\',
\'show_option_none\' => __(\'<span style=\"padding:0 20px;\">抱歉,暂无分类。</span>\'),
\'depth\' => 1,
\'taxonomy\' => \'category\',
\'walker\' => null
));
?>
1、本站所有资源来源于用户上传和网络,如有侵权请邮件联系站长!
2、分享目的仅供大家学习和交流,请不要用于商业用途!
3、本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解!
4、如有链接无法下载、失效或广告,请联系管理员处理!
5、本站资源售价只是赞助,收取费用仅维持本站的日常运营所需!
6、联系微信:A2022717!
袁博客 » WordPress如何在父分类获取所有子分类/二级分类
2、分享目的仅供大家学习和交流,请不要用于商业用途!
3、本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解!
4、如有链接无法下载、失效或广告,请联系管理员处理!
5、本站资源售价只是赞助,收取费用仅维持本站的日常运营所需!
6、联系微信:A2022717!
袁博客 » WordPress如何在父分类获取所有子分类/二级分类
常见问题FAQ
- 免费下载或者VIP会员专享资源能否直接商用?
- 本站所有资源版权均属于原作者所有,这里所提供资源均只能用于参考学习用,请勿直接商用。若由于商用引起版权纠纷,一切责任均由使用者承担。更多说明请参考 VIP介绍。
- 提示下载完但解压或打开不了?
- 你们有qq群吗怎么加入?
order viagra 50mg online sildenafil cheap cheap tadalafil 20mg
viagra sildenafil 50mg lamictal without prescription generic lamotrigine
order desyrel 100mg order sildenafil 100mg aurogra oral
online roulette wheel tadalafil 40mg pill cialis 10mg us
order cefuroxime 250mg pill careprost price generic robaxin
viagra buy online buy cialis 5mg pills tadalafil 40mg cheap
buy tadalafil tablets female viagra cvs sildenafil 100mg brand
cephalexin buy online cleocin 150mg over the counter order erythromycin 500mg without prescription
fluconazole price viagra 50mg pills for men sildenafil us
order metronidazole 400mg without prescription augmentin 1000mg cost bactrim 960mg over the counter
purchase simvastatin pill simvastatin 10mg ca proscar 1mg usa
tadalafil 20mg price order cipro 500mg generic ciprofloxacin us
tamsulosin 0.4mg pills order tamsulosin pills spironolactone canada
casino play real money casino roulette wheel online
order ranitidine 150mg online cheap buy celebrex 200mg generic order celecoxib online cheap
buy gloperba pills roulette casino online roulette free
order sumatriptan 25mg online cheap buy levaquin 500mg online buy avodart 0.5mg sale
purchase ozobax generic toradol order online toradol pills
cozaar 25mg brand nexium 20mg usa generic topamax 200mg
buy motilium 10mg pills tetracycline over the counter cyclobenzaprine 15mg uk
buy methotrexate 5mg generic reglan pills reglan sale
order zyloprim generic crestor 20mg without prescription order zetia 10mg generic
tadalafil 10mg drug order clopidogrel 150mg generic clopidogrel us
orlistat 120mg pill diltiazem us cheap acyclovir 800mg
order tadalafil sale cialis online sildenafil 20mg
dapoxetine usa purchase cytotec generic buy synthroid 100mcg
triamcinolone online order loratadine ca clarinex 5mg oral
tadalafil 20mg ca buy cialis tablets viagra sale
cheap clomid order clomiphene 100mg generic bonus casino
write my paper for me order viagra 100mg generic purchase sildenafil pills
buy lopressor generic metoprolol generic vardenafil 20mg generic
omeprazole price academia writers legitimate online slots for money
buy linezolid 600 mg sale roulette wheel online vegas casino online
viagra 50mg oral viagra 50mg ca lisinopril 5mg drug
order generic clozapine 100mg buy clozaril 50mg without prescription buy dexamethasone 0,0,5 mg online
olanzapine cheap olanzapine 10mg tablet valsartan 80mg price
order glucophage 1000mg pill buy lipitor 10mg generic cialis 40mg over the counter
sporanox uk progesterone 200mg for sale order tindamax 300mg online
buy chloroquine 250mg pills baricitinib 4mg drug purchase olumiant without prescription
cialis generic name generic tadalafil clomipramine 50mg uk
order generic furosemide hydroxychloroquine brand order hydroxychloroquine pills
cialis 40mg canada viagra fast shipping oral sildenafil 50mg
buy zithromax 500mg pill cost neurontin purchase neurontin generic
buy piracetam 800mg buy generic viagra 100mg best viagra sites online
isotretinoin 20mg generic prednisone 10mg pill order generic deltasone
buy provigil online cheap buy stromectol generic ivermectin 0.5% lotion
provera usa purchase hydrochlorothiazide generic cyproheptadine pill
avlosulfon sale nifedipine 30mg uk aceon over the counter
revia canada buy abilify online abilify 30mg canada
tadalafil 10mg order generic cialis 10mg amantadine oral
generic cialis canada cialis pills sildenafil 100mg uk
order imuran 100mcg without prescription pantoprazole cost sildenafil without a doctor’s prescription
zoloft online Buy viagra purchase viagra generic
buy molnupiravir 200mg generic order cefdinir 300 mg online lansoprazole 15mg generic
order zyban 150mg seroquel 100mg brand brand quetiapine
generic isosorbide 40mg digoxin 2250 mg usa buy telmisartan without prescription
prograf 5mg over the counter labetalol order urso over the counter
buy olmesartan without prescription benicar 20mg ca order generic diamox 250mg
purchase alendronate online cheap pepcid over the counter cost pepcid 20mg
order hytrin 5mg without prescription hytrin 5mg pill azulfidine us
buy buspirone for sale buspar 5mg cheap ditropan price
clonidine 0.1mg canada meclizine 25 mg us order spiriva pills
order generic altace order astelin online cheap oral azelastine 10ml
buy generic doxycycline clomiphene 50mg us brand furosemide
order modafinil pills acetazolamide canada buy acetazolamide 250 mg generic
accutane uk oral stromectol 3mg stromectol order online
cialis 10mg kaufen generika cialis 10mg kaufen ohne rezept sildenafil 50mg generika rezeptfrei kaufen
cheap deltasone 5mg prednisone 40mg pills sildenafil for sale online
tadalafil 10mg comprimГ© sildenafil 25mg sans ordonnance en france viagra 200mg prix
arimidex 1mg brand arimidex 1 mg canada sildenafil 100mg pills for sale
cialis 5mg canada cialis pricing sildenafil pills 100mg
buy indomethacin 50mg without prescription cefixime cost purchase trimox online
tadalafil 10mg pills buy avanafil 200mg for sale order voltaren without prescription
lamictal uk tretinoin over the counter retin tablet
buy sildenafil online cheap viagra sildenafil 25mg estradiol medication
fildena 100mg canada buy sildenafil 100mg sale buy methocarbamol 500mg online cheap
purchase ampicillin pill bactrim 480mg cost erythromycin cost
order aldactone 100mg pills cost valacyclovir 500mg fluconazole ca
buy dutasteride for sale cost flomax 0.4mg zofran 8mg sale
order levofloxacin without prescription levaquin 250mg cost