简体   繁体   中英

how to display url taxonomy in loop taxonomy wordpress?

i have a custom taxonomy genre, i want to show all taxonomy in genre.php page. when I try to use this code php echo $term->slug;

the result does not meet my expectations :

http://localhost/site/action

I want the result like this :

http://localhost/site/genre/action

I don't know where the error is, I've been looking but haven't found a solution.

this is my code 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();

You can use this code it will give results as per your requirement.

<?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();?>

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