繁体   English   中英

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

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM