how to display all categories in wordpress?

前端 未结 3 1704
逝去的感伤
逝去的感伤 2020-12-15 05:29

I used this code:

      $categories = wp_get_post_categories(get_the_ID());
      foreach($categories as $category){
          echo \'
3条回答
  •  自闭症患者
    2020-12-15 06:11

    In the code you gave us you are selected the categories selected for the specific post get_the_ID() is doing that part. However you would be best off using another function get_categories() https://developer.wordpress.org/reference/functions/get_categories/ which you would do like so:

    $categories = get_categories();
    foreach($categories as $category) {
       echo '';
    }
    

    You can also pass through arguments to be more specific (if needed) - see https://developer.wordpress.org/reference/functions/get_terms/ for details on what you can pass through

提交回复
热议问题