我只是试图在列表中显示一个特定的内容,在条件满足后,它应该显示在div中。这就是我所尝试的。

function the_meta() {
  if ( $keys = get_post_custom_keys() ) {
    echo "<ul class='post-meta'>\n";
    $i = 0;
    foreach ( (array) $keys as $key ) {

        $keyt = trim($key);

        if ( is_protected_meta( $keyt, 'post' ) )
            continue;

        $values = array_map('trim', get_post_custom_values($key));
        $value = implode($values,', ');
        echo apply_filters('the_meta_key', "<li id='slots_".$key."'><span class='post-meta-key'>$key:</span> $value</li>\n", $key, $value);

        if (++$i > 8)
           echo apply_filters('the_meta_key', "<div><span class='post-meta-key'>$key:</span> $value</div>\n", $key, $value);

    }
    echo "</ul>\n";
  }
}

我得到的是
<ul class='post-meta'>
   <li id='slots_Numeri_estratti_1'><span class='post-meta-key'>Numeri_estratti_1:</span> 22</li>
   <li id='slots_numeri_estratti_2'><span class='post-meta-key'>numeri_estratti_2:</span> 23</li>
   <li id='slots_numeri_estratti_3'><span class='post-meta-key'>numeri_estratti_3:</span> 24</li>
   <li id='slots_numeri_estratti_4'><span class='post-meta-key'>numeri_estratti_4:</span> 25</li>
   <li id='slots_numeri_estratti_5'><span class='post-meta-key'>numeri_estratti_5:</span> 26</li>
   <li id='slots_numeri_estratti_6'><span class='post-meta-key'>numeri_estratti_6:</span> 27</li>
   <li id='slots_numeri_estratti_7'><span class='post-meta-key'>numeri_estratti_7:</span> 28</li>
   <li id='slots_numeri_estratti_8'><span class='post-meta-key'>numeri_estratti_8:</span> Concorso Nr. 36 - Montepremi complessivo € 10.474.698,21</li>
   <li id='slots_numeri_estratti_9'><span class='post-meta-key'>numeri_estratti_9:</span> 21</li>
   <div id='slots_numeri_estratti_9'><span class='post-meta-key'>numeri_estratti_9:</span> 21</div>
   <li id='slots_numeri_estratti_10'><span class='post-meta-key'>numeri_estratti_10:</span> 33</li>
   <div id='slots_numeri_estratti_10'><span class='post-meta-key'>numeri_estratti_10:</span> 33</div>
</ul>

这些值显示了两次,一个在列表中,另一个在div中。我在google上搜索了几个小时,但没有任何结果可以解决它。有人请帮助我。谢谢!!

最佳答案

应该是这样的

if (++$i > 8)
    echo apply_filters('the_meta_key', "<div><span class='post-meta-key'>$key:</span> $value</div>\n", $key, $value);
else
    echo apply_filters('the_meta_key', "<li id='slots_".$key."'><span class='post-meta-key'>$key:</span> $value</li>\n", $key, $value);

而不是
echo apply_filters('the_meta_key', "<li id='slots_".$key."'><span class='post-meta-key'>$key:</span> $value</li>\n", $key, $value);

if (++$i > 8)
    echo apply_filters('the_meta_key', "<div><span class='post-meta-key'>$key:</span> $value</div>\n", $key, $value);

关于php - 循环不会停止,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/22686599/

10-12 05:44