Issue
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();
Solution
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();?>
Answered By - Dotsquares Answer Checked By - Marie Seifert (PHPFixing Admin)
 
 Posts
Posts
 
 
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.