[英]Is there any way to get only parent terms from custom taxonomy or category?
[英]Get images from custom taxonomy terms
好的,我不知道是否允許提出新問題。 但是我認為這與我之前的問題有所不同。 (如果沒有,請告訴我)。
我試圖從我的自定義分類學術語中獲取特色圖片。 昨天我走得很遠,但是我的客戶想添加團隊成員的姓名。 因此,我有點想回到這一方面。
我的主題由四個不同的可折疊面板組成。 具有自定義帖子類型和循環。
因此,我對ons_team
進行了自定義分類,因為我不想在每個面板上都顯示團隊成員。 因此,我選中了希望顯示團隊成員的ctp框。
但是,既然客戶想要添加團隊成員的姓名,我不得不使用其他代碼。 昨天我可以使用此代碼。
<?php $terms = get_the_terms( $post->ID , 'ons_team' );
print apply_filters( 'taxonomy-images-list-the-terms', '', array(
'before' => '<div class="ons-team">',
'after' => '</div>',
'before_image' => '<span>',
'after_image' => '</span>',
'image_size' => 'detail',
'taxonomy' => 'ons_team',
) );
foreach ( $terms as $term ) {
$term_link = get_term_link( $term, 'ons_team' );
if( is_wp_error( $term_link ) )
continue;
}
?>
這只會在我選中框的面板上顯示團隊成員。 但是我無法在此代碼中添加團隊成員的姓名。
所以我使用以下代碼在單個頁面上工作:
<?php
// List of image links
$terms = apply_filters( 'taxonomy-images-get-terms', '', array( 'taxonomy' => 'ons_team' ) );
foreach( (array) $terms as $term) {
echo '<div class="col s6 m6 l3 teamimage"><a href="' . esc_attr( get_term_link( $term ) ) . '" title="' . sprintf( __( "%s" ), $term->name ) . '" ' . '>' . wp_get_attachment_image( $term->image_id, 'destacado-proyectos-home' ) . '</a>';
echo '<h2 class="truncate">' . sprintf( __( "%s" ), $term->name ) . '</h2>';
echo '</div>';
}
?>
但是,如果我在面板上使用該代碼,我希望顯示信息。 它顯示在所有面板上,而不是我要顯示的唯一面板上。
我嘗試將兩者結合使用,但是每個面板仍然顯示圖像和名稱。
<?php $terms = get_the_terms( $post->ID , 'ons_team' );
$terms = apply_filters( 'taxonomy-images-get-terms', '', array( 'taxonomy' => 'ons_team' ) );
foreach( (array) $terms as $term) {
echo '<div class="col s6 m6 l3 teamimage"><a href="' . esc_attr( get_term_link( $term ) ) . '" title="' . sprintf( __( "%s" ), $term->name ) . '" ' . '>' . wp_get_attachment_image( $term->image_id, 'destacado-proyectos-home' ) . '</a>';
echo '<h2 class="truncate">' . sprintf( __( "%s" ), $term->name ) . '</h2>';
echo '</div>';
}
foreach ( $terms as $term ) {
$term_link = get_term_link( $term, 'ons_team' );
if( is_wp_error( $term_link ) )
continue;
}
?>
將代碼放在foreach或任何其他地方類型之間會破壞代碼。 是否有可能因為我大量使用$ term / $ terms而不起作用?
像這樣使用它:
<?php $terms = get_the_terms( $post->ID , 'ons_team' );
foreach ( $terms as $term ) {
$term_link = get_term_link( $term, 'ons_team' );
$terms = apply_filters( 'taxonomy-images-get-terms', '', array( 'taxonomy' => 'ons_team' ) );
foreach( (array) $terms as $term) {
echo '<div class="col s6 m6 l3 teamimage"><a href="' . esc_attr( get_term_link( $term ) ) . '" title="' . sprintf( __( "%s" ), $term->name ) . '" ' . '>' . wp_get_attachment_image( $term->image_id, 'destacado-proyectos-home' ) . '</a>';
echo '<h2 class="truncate">' . sprintf( __( "%s" ), $term->name ) . '</h2>';
echo '</div>';
}
if( is_wp_error( $term_link ) )
continue;
}
?>
有點工作,但隨后連續10次向團隊成員展示...
任何幫助深表感謝!
解決了!
如果人們需要,這是正確的代碼:
<div class="teamleden over-ons-ul">
<div class="center-align">
<div class="row">
<?php
$terms = get_the_terms( $post->ID , 'ons_team' );
if ( $terms != null ){
$terms = apply_filters( 'taxonomy-images-get-terms', '', array( 'taxonomy' => 'ons_team' ) );
foreach( (array) $terms as $term) {
echo '<div class="col s6 m6 l3 teamimage"><a href="' . esc_attr( get_term_link( $term ) ) . '" title="' . sprintf( __( "%s" ), $term->name ) . '" ' . '>' . wp_get_attachment_image( $term->image_id, 'destacado-proyectos-home' ) . '</a>';
echo '<h2 class="truncate">' . sprintf( __( "%s" ), $term->name ) . '</h2>';
echo '</div>';
}
foreach( $terms as $term ) {
unset($term);
} } ?>
</div>
</div>
</div>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.