如何以正确的方式关闭我的php标记?
我有一段php代码,我需要以正确的方式关闭php标记,但我不确定最好的方式是什么,因为我把html和php混淆了。我已经从我不确定的零件上移除了标签如何以正确的方式关闭我的php标记?,php,html,Php,Html,我有一段php代码,我需要以正确的方式关闭php标记,但我不确定最好的方式是什么,因为我把html和php混淆了。我已经从我不确定的零件上移除了标签 <div id="fphItems"> $i = 1; query_posts( 'posts_per_page=4&cat=3' ); if ( have_posts() ) { while ( have_posts()
<div id="fphItems">
$i = 1;
query_posts( 'posts_per_page=4&cat=3' );
if ( have_posts() ) {
while ( have_posts() ) {
the_post();
if ( $i < 4 ) {
echo '<div class="fphItem">';
}
else {
echo '<div class="fphLastItem">';
}
if ( has_post_thumbnail() ) {
the_post_thumbnail();
<div class="fphItemTitle">
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a>
</div>
}
}
}
else {
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
}
<?php wp_reset_query();
</div>
$i=1;
查询帖子(“每页帖子=4&cat=3”);
如果(have_posts()){
while(have_posts()){
_post();
如果($i<4){
回声';
}
否则{
回声';
}
如果(具有\u post\u缩略图()){
_post_缩略图();
}
}
}
否则{
}
使用这个修改过的代码。查看代码中需要适当打开/关闭的注释
<div id="fphItems">
<?php //<--- Open Here
$i = 1;
query_posts( 'posts_per_page=4&cat=3' );
if ( have_posts() ) {
while ( have_posts() ) {
the_post();
if ( $i < 4 ) {
echo '<div class="fphItem">';
}
else {
echo '<div class="fphLastItem">';
}
if ( has_post_thumbnail() ) {
the_post_thumbnail();
?> <!-- Close here -->
<div class="fphItemTitle">
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a>
</div>
<?php // Open here again
}
}
}
else {
echo "<p>";
echo('Sorry, no posts matched your criteria.');
echo "</p>";
}
wp_reset_query(); ?> <!-- Close here -->
</div>
无论何时使用php代码,都需要打开和关闭php标记
<div id="fphItems">
<?php
$i = 1;
query_posts( 'posts_per_page=4&cat=3' );
if ( have_posts() ) {
while ( have_posts() ) {
the_post();
if ( $i < 4 ) {
echo '<div class="fphItem">';
}
else {
echo '<div class="fphLastItem">';
}
if ( has_post_thumbnail() ) {
the_post_thumbnail();
?>
<div class="fphItemTitle">
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a>
</div>
<?php
}
}
}
else {
?>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<?php
}
?>
<?php wp_reset_query(); ?>
</div>
尝试将?>
放在wp\u reset\u query()的末尾代码>这是一个建议,不是解决方案。试着用监督的标准编写代码。我没有选择你的答案作为最佳答案,因为你将“对不起,没有帖子符合你的标准”)改为“回音(对不起,没有帖子符合你的标准”);,这是不正确的,因为它是一个函数。thx btw!