问题描述
这是在 wordpress 中
<?PHP
//first get the current term
$current_term = get_term_by( 'slug',get_query_var( 'term' ),get_query_var( 'taxonomy' ) );
//then set the args for wp_list_categories
$args = array(
'child_of' => $current_term->term_id,'taxonomy' => $current_term->taxonomy,'hide_empty' => 0,'hierarchical' => true,'depth' => 1,'title_li' => '',);
?>
<?PHP foreach ( $args as $arg ) { ?>
<div class="col-md-6">
<article>
<header class="entry-header">
<h2><?PHP wp_list_categories( $args ); ?></h2>
</header>
</article>
</div>
<?PHP } ?>
请任何人都可以帮助它会很棒
<?PHP
$cat_args = array(
'taxonomy' => 'business_categories','orderby' => 'name','order' => 'ASC','number'=> 2,);
$categories = get_categories( $cat_args );
foreach ( $categories as $category ) {
?>
<div class="col-md-6">
<h3>
<a href="<?= get_category_link( $category->term_id ) ?>"><?= $category->name ?></a>
</h3>
<p>
<a href="<?= get_category_link( $category->term_id ) ?>"><?= $category->category_description ?></a>
</p>
</div>
<!-- <pre>
<?PHP print_r( $categories ); ?>
</pre> -->
<?PHP } ?>
解决方法
试试这样的东西
<?php
$categories = get_categories( $args );
?>
...
<?php foreach ( $categories as $term ): ?>
<div class="col-md-6">
<article>
<header class="entry-header">
<h2><?php echo $term->name; ?></h2>
<p><?php echo $term->description; ?></p>
</header>
</article>
</div>
<?php endforeach; ?>
,
我得到了答案
get get_category_link 只显示 HTML 标题输出
<?php
$current_term = get_term_by( 'slug',get_query_var( 'term' ),get_query_var( 'taxonomy' ) );
$args = get_terms( array(
'orderby' => 'name','order' => 'ASC','taxonomy' => $current_term->taxonomy,'child_of' => $current_term->term_id,) );
foreach ( $args as $arg ) { ?>
<div class="col-md-6">
<article>
<header class="entry-header">
<h2><a href="<?= get_term_link( $arg->term_id ) ?>"><?php echo $arg->name ?></a></h2>
</header>
<p><a href="<?= get_term_link( $arg->term_id ) ?>"( $arg->term_id ) ?>"><?php echo $arg->description ?></a></p>
</article>
</div>
<?php } ?>
</div>
</div>
希望对遇到类似情况的人有所帮助