doutale7115 2014-08-13 16:10
浏览 48
已采纳

当我尝试将循环输出插入无序列表时,为什么会出现语法错误?

I am very new in PHP and WordPress development and I have the following problem trying to insert some HTML code into the posts loop.

I tried something like it:

<?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;
?>

As you can see I want an unordered list (the < ul>**tag) and into it I want put the one list element (the **< li> tag) for each interation of the while cycle but Aptana Studio give me a syntax error message on the < ul> and on the < li>

Why? Where is the problem? How can I fix it?

Tnx

  • 写回答

1条回答 默认 最新

  • dpqvwgr74759 2014-08-13 16:19
    关注

    If you aren't closing your PHP tags, you need to use echo calls to push output to the 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;
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料