我有一個自定義分類流派,我想在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();
uj5u.com熱心網友回復:
您可以使用此代碼,它將根據您的要求給出結果。
<?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();?>
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/475533.html
