在一个页面中显示所有WordPress类别

时间:2018-08-05 作者:omid chahardoli

我想在一个页面中显示所有WordPress类别。我使用此代码:

<?php
 $categories = get_categories( array(
 \'orderby\' => \'name\',
 \'order\'   => \'ASC\',
 \'exclude\' => \'1,116\',

    ) );
  foreach  ($categories as $category) {
      echo \'<div class="item_product">\';
      // display category image
              echo \'<div class="image_wrapper is-image">\';
                  echo do_shortcode(sprintf(\'[wp_custom_image_category term_id="%s"]\',$category->term_id));
            echo \'</div>\';
            // display category name 
              echo \'<div class="desc_left">\';
                    echo \'<h2 class="podcast_h2"><a href=" \' .get_permalink($category->ID). \' "> \'.$category->name.\' </a></h2>\';
              echo \'</div>\';
          echo \'</div>\';

} ?>
但是,每个类别都链接到与类别列表相同的页面(example.com/list category)
我希望每个类别都链接到该类别

1 个回复
SO网友:nmr

要获取类别链接,请使用函数get_category_link (doc here).
功能get_permalink 用于posts.

echo \'<h2 class="podcast_h2"><a href=" \' .get_category_link($category->term_id). \' "> \'.$category->name.\' </a></h2>\'

结束

相关推荐

Media Library Categories

我使用以下内容将类别分配给我的WordPress媒体库(在functions.php):function wptp_add_categories_to_attachments() { register_taxonomy_for_object_type( \'category\', \'attachment\' ); } add_action( \'init\' , \'wptp_add_categories_to_attachments\' ); 每个媒体库项目都