为什么在尝试将循环输出插入无序列表时出现语法错误


Why I obtain a syntax error when I try to insert a cycle output into an unordered list?

我是PHP和WordPress开发的新手,我有以下问题,试图将一些HTML代码插入posts循环。

我试过这样做:

<?php
if (have_posts()) :
    <ul>
    // Start the Loop.
    while (have_posts()) : the_post();
        /*
         * Include the post format-specific template for the content. If you want to
         * use this in a child theme, then include a file called called content-___.php
         * (where ___ is the post format) and that will be used instead.
         */
        <li>
        get_template_part('contentArchive', get_post_format());
        </li>
    endwhile;
    </ul>

    endwhile;
?>

你可以看到我想要一个无序列表 (

    **标签),然后放入一个列表元素(**
标签),但Aptana Studio给我一个语法错误消息在
    <李>

    为什么?问题在哪里?我该怎么修理它?

    Tnx

    如果您没有关闭PHP标记,则需要使用echo调用将输出推送到DOM。

    <?php
    if (have_posts()) :
        echo '<ul>';
        // Start the Loop.
        while (have_posts()) : the_post();
            /*
             * Include the post format-specific template for the content. If you want to
             * use this in a child theme, then include a file called called content-___.php
             * (where ___ is the post format) and that will be used instead.
             */
            echo '<li>';
            get_template_part('contentArchive', get_post_format());
            echo '</li>';
        endwhile;
        echo '</ul>';
    
        endwhile;
    ?>