我正在为自定义WordPress主题编码页面,并且正在使用PHP和Advanced Custom Fields创建页面的动态内容。我所有的div
标签都有一个开头和结尾,但是Google似乎早早结束了div
标签,因为它与错误的end标签配合使用使我的内容看起来很奇怪。有谁知道它为什么这样做以及如何解决?
我已经尝试匹配所有标签,但找不到一个未正确结束的标签,所以我对标签的含义感到迷茫。
这是我的代码。我已经尽力减少了,但是查看Div配对需要所有这些:
<div class="smaller-width center top">
<div id="project-nav" class="title-section">
<h1>Work.</h1>
<nav id="project-filters">
<button onClick="filterProj('All')" class="news-filter" ><p>All</p></button>
<?php foreach($allCategories as $category) {
echo '<button onClick="filterProj('."'". $category->name ."'".')" class="news-filter" ><p>' . $category->name . '</p></button>';
} ?>
</nav>
</div>
<div class="projcont full center">
<div class="news-inner">
<div class="clr"></div>
<div id="projects-section">
<?php
foreach ($postslist as $post) : setup_postdata($post); ?>
<?php if (has_post_thumbnail( $post->ID ) ):
$image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' );
?>
<div class="project-post" data-categories="<?php
foreach(wp_get_post_terms($post->ID, 'Project_Category', array("fields" => "all")) as $category) {
echo $category->name . ',';
} ?>">
<a class="single-project" href="<?php the_permalink() ?>">
<div class="project-inside" style="background-image: url( <?php echo $image[0]; ?>);">
</div>
<p>
<?php the_title(); ?><br>
<span id="tag">
<?php foreach(wp_get_post_terms($post->ID, 'Project_Category', array("fields" => "all")) as $category) {
echo $category->name . ' ';
} ?>
</span>
<i class="fas fa-angle-right project-arrow"></i>
</p>
</a>
<?php endif; ?>
</div>
<?php endforeach; ?>
</div>
</div>
<div id="load">
<button href="#" id="loadMore">VIEW MORE</button>
</div>
</div>
</div>
关于什么可能会破坏它,这里是否还有其他内容?
编辑:这是Google早点结束我的div的屏幕截图...
如您所见,最后2个project-post
ID应该在project section
答案 0 :(得分:1)
格式化是您的朋友。我已经用VS Code格式化了您的代码,并且可以更清楚地了解您的问题所在。如果和每个语句之间的结尾处的div位于错误的位置。我相信这就是导致您出现问题的原因。
<div class="smaller-width center top">
<div id="project-nav" class="title-section">
<h1>Work.</h1>
<nav id="project-filters">
<button onClick="filterProj('All')" class="news-filter" ><p>All</p></button>
<?php foreach ($allCategories as $category) {
echo '<button onClick="filterProj('."'". $category->name ."'".')" class="news-filter" ><p>' . $category->name . '</p></button>';
} ?>
</nav>
</div>
<div class="projcont full center">
<div class="news-inner">
<div class="clr"></div>
<div id="projects-section">
<?php foreach ($postslist as $post) : setup_postdata($post); ?>
<?php if (has_post_thumbnail($post->ID)):
$image = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'single-post-thumbnail');
?>
<div class="project-post"
data-categories="
<?php
foreach (wp_get_post_terms($post->ID, 'Project_Category', array("fields" => "all")) as $category) {
echo $category->name . ',';
} ?>">
<a class="single-project" href="<?php the_permalink() ?>">
<div class="project-inside" style="background-image: url( <?php echo $image[0]; ?>);"></div>
<p>
<?php the_title(); ?><br>
<span id="tag">
<?php foreach (wp_get_post_terms($post->ID, 'Project_Category', array("fields" => "all")) as $category) {
echo $category->name . ' ';
} ?>
</span>
<i class="fas fa-angle-right project-arrow"></i>
</p>
</a>
</div>
<?php endif; ?>
<?php endforeach; ?>
</div>
</div>
</div>
<div id="load">
<button href="#" id="loadMore">VIEW MORE</button>
</div>
</div>
</div>