简体   繁体   中英

How To Display Categories on front-page.php

I was wondering if there was a way to loop through WordPress categories like there is for posts. I am trying to display these categories on the front-page.php file of my custom theme. Is there any way to do this? I have tried using functions like wp_list_categories() and different variations of it. However, it only returns the “Uncategorised” category and non of the others.

I was also wondering if there was a way (in this supposed loop or function to display all the different categories) to get the $term_id of the category I have uploaded custom images for each category and would like to grab those as well. Is that a possibility?

I think your problem with displaying categories via wp_list_categories() is that by default this function does not display categories with no posts.

Try use this function with parameter "hide_empty=0"

<?php wp_list_categories('hide_empty=0');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM