Home > database >  how to display url taxonomy in loop taxonomy wordpress?
how to display url taxonomy in loop taxonomy wordpress?

Time:05-16

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 >
  <div >
    <div >
      <div id="list_categories_categories_list">
        <?php get_template_part( 'template-parts/ads-bottom' ); ?>
        <div >
          <h1>
            Genre                   
          </h1>
        </div>
        <div >
          <div >
            <div  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  href="<?php echo $term->slug; ?>" title="<?php echo $term->name; ?>">
                    <div >
                    <?php if ( $image != '' ) {
                        echo wp_get_attachment_image( $image, "", ["class" => "thumb"]);
                    }
                    ?>
                    </div>
                    <strong ><?php echo $term->name; ?></strong>
                    <div >
                    <div >0 videos</div>
                    <div >
                        81%
                    </div>
                    </div>
                </a>
              <?php } ?>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>
<?php 
get_footer();

CodePudding user response:

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

<?php
/*
Template Name: Genre
*/
get_header(); ?>
<div >
  <div >
    <div >
      <div id="list_categories_categories_list">
        <?php get_template_part( 'template-parts/ads-bottom' ); ?>
        <div >
          <h1>
            Genre                   
          </h1>
        </div>
        <div >
          <div >
            <div  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  href="<?php echo get_term_link($term->term_id); ?>" title="<?php echo $term->name; ?>">
                    <div >
                    <?php if ( $image != '' ) {
                        echo wp_get_attachment_image( $image, "", ["class" => "thumb"]);
                    }
                    ?>
                    </div>
                    <strong ><?php echo $term->name; ?></strong>
                    <div >
                    <div >0 videos</div>
                    <div >
                        81%
                    </div>
                    </div>
                </a>
              <?php } ?>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>
<?php 
get_footer();?>
  • Related