从自定义分类术语中获取图像


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>