我是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;
?>
正如您所看到的,我想要一个无序列表(&lt; ul&gt; **标记)并且我想要放入一个列表元素(**&lt; li&gt; 标记)对于while循环的每次交互,但Aptana Studio在&lt; 上给我一个语法错误消息ul&gt; 以及&lt; li&gt;
为什么呢?问题出在哪儿?我该如何解决?
TNX
答案 0 :(得分:1)
如果您没有关闭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;
?>