繁体   English   中英

如何在循环分类 wordpress 中显示 url 分类?

[英]how to display url taxonomy in loop taxonomy wordpress?

我有一个自定义分类流派,我想在genre.php 页面中显示所有分类。 当我尝试使用此代码时 php echo $term->slug;

结果不符合我的期望:

http://localhost/site/action

我想要这样的结果:

http://localhost/site/genre/action

我不知道错误在哪里,我一直在寻找但没有找到解决方案。

这是我的代码genre.php

<?php
/*
Template Name: Genre
*/
get_header(); ?>
<div class="content">
  <div class="main-content">
    <div class="main-container">
      <div id="list_categories_categories_list">
        <?php get_template_part( 'template-parts/ads-bottom' ); ?>
        <div class="headline">
          <h1>
            Genre                   
          </h1>
        </div>
        <div class="box">
          <div class="list-categories">
            <div class="margin-fix" id="list_categories_categories_list_items">
              <?php
                $terms = get_terms( array(
                    'taxonomy' => 'genre',
                    'hide_empty' => false,
                    'number' => 20
                ) );
                
                foreach ($terms as $term){ ?>
                <?php $image = get_term_meta( $term->term_id, 'image', true ); ?>
                <a class="item" href="<?php echo $term->slug; ?>" title="<?php echo $term->name; ?>">
                    <div class="img">
                    <?php if ( $image != '' ) {
                        echo wp_get_attachment_image( $image, "", ["class" => "thumb"]);
                    }
                    ?>
                    </div>
                    <strong class="title"><?php echo $term->name; ?></strong>
                    <div class="wrap">
                    <div class="videos">0 videos</div>
                    <div class="rating positive">
                        81%
                    </div>
                    </div>
                </a>
              <?php } ?>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>
<?php 
get_footer();

您可以使用此代码,它将根据您的要求给出结果。

<?php
/*
Template Name: Genre
*/
get_header(); ?>
<div class="content">
  <div class="main-content">
    <div class="main-container">
      <div id="list_categories_categories_list">
        <?php get_template_part( 'template-parts/ads-bottom' ); ?>
        <div class="headline">
          <h1>
            Genre                   
          </h1>
        </div>
        <div class="box">
          <div class="list-categories">
            <div class="margin-fix" id="list_categories_categories_list_items">
              <?php
                $terms = get_terms( array(
                    'taxonomy' => 'genre',
                    'hide_empty' => false,
                    'number' => 20
                ) );
                
                foreach ($terms as $term){ ?>
                <?php $image = get_term_meta( $term->term_id, 'image', true ); ?>
                <a class="item" href="<?php echo get_term_link($term->term_id); ?>" title="<?php echo $term->name; ?>">
                    <div class="img">
                    <?php if ( $image != '' ) {
                        echo wp_get_attachment_image( $image, "", ["class" => "thumb"]);
                    }
                    ?>
                    </div>
                    <strong class="title"><?php echo $term->name; ?></strong>
                    <div class="wrap">
                    <div class="videos">0 videos</div>
                    <div class="rating positive">
                        81%
                    </div>
                    </div>
                </a>
              <?php } ?>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>
<?php 
get_footer();?>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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