如何将foreach循环放在标记内

时间:2016-08-05 15:31:08

标签: php html

如何在标记内放置foreach循环?

这是代码:

Button

我一直收到错误。你能帮我使用PROPER语法吗?

3 个答案:

答案 0 :(得分:2)

foreach( $designer_posts as $designer_post ) {
        $tags = get_the_tags($designer_post->ID);
        $imageThumb = get_the_post_thumbnail( $designer_post->ID, "thumbnail" );

        $html .= '<tr>';
        $html .= '<th scope="row">View</th>';
        $html .= '<td><p>'.$designer_post->post_title.'</p></td>';   
        $html .= '<td>';
            foreach() {
                $html .= 'The rest of the HTML code';
            }
        $html .= '</td>';                     
        $html .= '<td>'.$imageThumb.'</td>';                  
        $html .= '</tr>';                    
}

答案 1 :(得分:1)

我想你想这样做:

foreach( $designer_posts as $designer_post ) {
        $tags = get_the_tags($designer_post->ID);
        $imageThumb = get_the_post_thumbnail( $designer_post->ID, "thumbnail" );

        $html .= '<tr>';
        $html .= '<th scope="row">View</th>';
        $html .= '<td><p>'.$designer_post->post_title.'</p></td>';   
        $html .= '<td>';
        foreach($designer_post as $test) {
           $html .= 'what you want fraté';
        }
        $html .= '</td>';                        
        $html .= '<td>'.$imageThumb.'</td>';                  
        $html .= '</tr>';                    
}

答案 2 :(得分:0)

<?php     
foreach( $designer_posts as $designer_post ) {
        $tags = get_the_tags($designer_post->ID);
        $imageThumb = get_the_post_thumbnail($designer_post->ID,"thumbnail");
?>

        <tr>
         <th scope="row">View</th>
         <td><p> <?php print $designer_post->post_title; ?></p></td>   
         <td>
             <?php foreach($array_data as $data) {
                print $data;
             } ?>
         </td>                     
         <td> <?php print $imageThumb; ?></td>                  
        </tr>                    
<?php } ?>