v2.5.2
Giriş yap

Bir dizede 2 foreach Döndürme

kreawich
364 defa görüntülendi

Merhabalar,

Aşağıdaki şekilde 2 adet foreach döngüsü mevcut, Ben sadece tek bir döngü olarak kullanmak istiyorum. bunu nasıl yapabilirim?

Birincisi;

   <?php 
				$categories = get_the_terms( $post_id, array ( 'rtcl_category', 'category' ));
				if ( ! empty( $categories ) ) {
				foreach ( $categories as $category ) { 
				echo '<li><a href="' . get_category_link( $category->term_id ) . '"><i class="fa fa-tag"></i>' . $category->name . '</a></li>';
				}
				}  			
		       ?>

İkincisi;

    if ( count( $fields ) ) :
	ob_start();
	foreach ( $fields as $field ) :
		$field = new RtclCFGField( $field->ID );
		$value = $field->getFormattedCustomFieldValue( $listing_id );

		if ( $value ) :
			?>
            <li>
				<?php if ( $field->getIconClass() ): ?>
                    <i class='rtcl-icon rtcl-icon-<?php echo esc_html( $field->getIconClass() ); ?>'></i>
				<?php else: ?>
                    <span class='listable-label'><?php echo esc_html( $field->getLabel() ); ?></span>
				<?php endif; ?>
                <span class='listable-value'>
                    <span class="prefix">
                        <?php
                        if ( $field->getLabel() == 'Bedroom' ) {
	                        echo esc_html__( 'Beds', 'homlisti' );
                        }

                        if ( $field->getLabel() == 'Bath' ) {
	                        echo esc_html__( 'Baths', 'homlisti' );
                        }
                        ?>
                    </span>

                    <span class="value">
                    <?php
                    $value = strlen( $value ) == 1 ? '<span>0</span>' . $value : $value;
                    echo stripslashes_deep( $value );
                    ?>
                    </span>

                    <span class="suffix">
                    <?php if ( $field->getLabel() == 'Sqft' ) {
	                    echo esc_html( $field->getLabel() );
                    } ?>
                    </span>
                </span>
            </li>
		<?php endif;
	endforeach;

	$fields_html = ob_get_clean();
	if ( $fields_html ) {
		printf( '<ul class="product-features">%s</ul>', $fields_html );
	}
endif;

sorun çözülmüştür.

Cevap yaz
Cevaplar (1)
desrana
829 gün önce

Biri kategori biri başka bir datayı parçalıyor, yani ayrı olmasının izahı yok. Göremediğimiz 2 datanın ortak noktası nedir ?