$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>php - Loop stopped working|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

php - Loop stopped working

matteradmin11PV0评论

I have a huge issue and I broke my had trying to find the correct solution. I have a following loop code. This loop is inside my page-product.php file:

<?php 
    $terms = get_the_terms( get_the_ID(), 'colour' );
    if ( $terms && ! is_wp_error( $terms ) ) :
?>
<section class="colour__chart">
    <div class="container">
        <div class="row">
            <div id="color-chart">
               <h2>Colour Chart</h2>
                <?
            $terms = get_the_terms( get_the_ID(), 'colour' );
if( $terms && ! is_wp_error( $terms ) ){
    foreach( $terms as $term ){

        echo get_field( 'name', 'colour_' . $term->term_id ); 

        echo '<div class="col-md-2 col-sm-4 col-xs-4 text-center">';
        echo '<div class="color-chart__item" style="background-color:' . get_field( 'colour_acf', 'colour_' . $term->term_id ) . '"></div>';
        echo '<p>' . $term->name . '</p>' ;
        echo '</div>' ;
    }
}
            ?>
            </div>
        </div>
    </div>
</section>
<?php endif; ?>

and everything worked great before today. Suddenly the loop stopped working and instead of its correct displaying in the front-end I see only this text:

'; echo '
'; echo '
' . $term->name . '

' ; echo '

I've attached a screenshot also. Would appreciate any help.

I have a huge issue and I broke my had trying to find the correct solution. I have a following loop code. This loop is inside my page-product.php file:

<?php 
    $terms = get_the_terms( get_the_ID(), 'colour' );
    if ( $terms && ! is_wp_error( $terms ) ) :
?>
<section class="colour__chart">
    <div class="container">
        <div class="row">
            <div id="color-chart">
               <h2>Colour Chart</h2>
                <?
            $terms = get_the_terms( get_the_ID(), 'colour' );
if( $terms && ! is_wp_error( $terms ) ){
    foreach( $terms as $term ){

        echo get_field( 'name', 'colour_' . $term->term_id ); 

        echo '<div class="col-md-2 col-sm-4 col-xs-4 text-center">';
        echo '<div class="color-chart__item" style="background-color:' . get_field( 'colour_acf', 'colour_' . $term->term_id ) . '"></div>';
        echo '<p>' . $term->name . '</p>' ;
        echo '</div>' ;
    }
}
            ?>
            </div>
        </div>
    </div>
</section>
<?php endif; ?>

and everything worked great before today. Suddenly the loop stopped working and instead of its correct displaying in the front-end I see only this text:

'; echo '
'; echo '
' . $term->name . '

' ; echo '

I've attached a screenshot also. Would appreciate any help.

Share Improve this question asked Feb 13, 2019 at 19:39 JamdevJamdev 1175 bronze badges 3
  • 1 did you update php? Maybe try changing <h2>color chart</h2 <? to<h2>color chart</h2 <?php – rudtek Commented Feb 13, 2019 at 20:12
  • @rudtek yeah that helped! Thanks a lot my friend. Please, post it as a separate comment so I could mark it as a solved. – Jamdev Commented Feb 13, 2019 at 20:22
  • done. Thanks, let me know if there's anything else. – rudtek Commented Feb 13, 2019 at 21:03
Add a comment  | 

1 Answer 1

Reset to default 2

While <? was once a valid php opener, you should be using <?php.

Try changing this line:

           <h2>Colour Chart</h2>
            <?

to

           <h2>Colour Chart</h2>
            <?php

That should allow the php to be read correctly.

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far