gpt4 book ai didi

php - 循环后关闭div

转载 作者:行者123 更新时间:2023-11-28 01:46:39 30 4
gpt4 key购买 nike

我正在构建一个显示不同类别帖子的页面。

循环没有问题,帖子显示正确,但第二个类别标题“热门故事”卡在“主要类别”部分。我似乎无法关闭该部分。我知道这听起来很疯狂,但我看不出我做错了什么或做错了什么。

网址:test site

.main-categories {
width: 100%;
max-width: 1280px;
padding: 60px 70px 36px;
margin-bottom:500px;
margin-left:5em;
margin-right:5em;
}

.main-categories ul li {
list-style:none;
}

.trending-categories {
width: 100%;
max-width: 1280px;
padding: 260px 70px 36px;
margin-bottom:500px;
margin-left:5em;
margin-right:5em;
}

.trending-categories ul li {
list-style:none;
}

.cat-row {
width: 20%;
float: left;
}

.cat-title {
max-width: 220px;
}

.cat-title h4 {
font-size: 22px;
font-weight: 900;
text-align:center;
color:#000;
}

.posts li:nth-child(3) {
color:#000;
font-size:20px;
font-weight:900;
}

.posts li:nth-child(7) {
color:#000;
font-size:20px;
font-weight:900;
}

.posts li:nth-child(4) {
margin-bottom:20px;
}

.posts li:nth-child(8) {
margin-bottom:20px;
}

ul.posts {
max-width:220px;
}

span.author {
color:#d6b4b1 !important;
}

.cat-label h2 {
overflow: hidden;
text-align: center;
}
.cat-label h2:before,
.cat-label h2:after {
background-color: #000;
content: "";
display: inline-block;
height: 1px;
position: relative;
vertical-align: middle;
width: 50%;
}
.cat-label h2:before {
right: 0.5em;
margin-left: -50%;
}
.cat-label h2:after {
left: 0.5em;
margin-right: -50%;
}

section.cat-label {
max-width: 1000px;
margin-left: auto;
margin-right: auto;
margin-top: 75px;
}

section.cat-label h2 {
font-size:20px;
}

.cat-label-2 h2 {
overflow: hidden;
text-align: center;
}
.cat-label-2 h2:before,
.cat-label-2 h2:after {
background-color: #000;
content: "";
display: inline-block;
height: 1px;
position: relative;
vertical-align: middle;
width: 50%;
}
.cat-label-2 h2:before {
right: 0.5em;
margin-left: -50%;
}
.cat-label-2 h2:after {
left: 0.5em;
margin-right: -50%;
}

section.cat-label-2 {
max-width: 1000px;
margin-left: auto;
margin-right: auto;
margin-top: 75px;
}

section.cat-label-2 h2 {
font-size:20px;
}
<?php /* Template Name: Fashion-Home */ ?>

<?php get_header(); ?>

<section class="cat-label">
<h2>Categories</h2>
</section>

<section class="main-categories">
<div class="cat-row">
<div class="cat-title">
<h4>Fashion</h4></div>

<?php query_posts( 'category_name=fashion&posts_per_page=2' ); ?>

<ul class="posts">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>

<li><a href="<?php the_permalink(); ?>"><?php the_post_thumbnail( array(220,220) ); ?></a></li>
<li><?php echo get_the_date('d.m.Y'); ?></li>
<li><a href='<?php the_permalink() ?>'><?php the_title(); ?></a></li>
<li><p>by <span class="author"><?php the_author(); ?></span></p></li>


<?php endwhile; ?>
<?php endif; ?>
<?php wp_reset_query(); ?>

</ul>
</div>

<div class="cat-row">
<div class="cat-title">
<h4>Travel</h4></div>

<?php query_posts( 'category_name=Travel&posts_per_page=2' ); ?>

<ul class="posts">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>

<li><a href="<?php the_permalink(); ?>"><?php the_post_thumbnail( array(220,220) ); ?></a></li>
<li><?php echo get_the_date('d.m.Y'); ?></li>
<li><a href='<?php the_permalink() ?>'><?php the_title(); ?></a></li>
<li><p>by <span class="author"><?php the_author(); ?></span></p></li>


<?php endwhile; ?>
<?php endif; ?>
<?php wp_reset_query(); ?>

</ul>
</div>

<div class="cat-row">
<div class="cat-title">
<h4>Interior</h4></div>

<?php query_posts( 'category_name=Travel&posts_per_page=2' ); ?>

<ul class="posts">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>

<li><a href="<?php the_permalink(); ?>"><?php the_post_thumbnail( array(220,220) ); ?></a></li>
<li><?php echo get_the_date('d.m.Y'); ?></li>
<li><a href='<?php the_permalink() ?>'><?php the_title(); ?></a></li>
<li><p>by <span class="author"><?php the_author(); ?></span></p></li>


<?php endwhile; ?>
<?php endif; ?>
<?php wp_reset_query(); ?>

</ul>
</div>

<div class="cat-row">
<div class="cat-title">
<h4>Work</h4></div>

<?php query_posts( 'category_name=Travel&posts_per_page=2' ); ?>

<ul class="posts">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>

<li><a href="<?php the_permalink(); ?>"><?php the_post_thumbnail( array(220,220) ); ?></a></li>
<li><?php echo get_the_date('d.m.Y'); ?></li>
<li><a href='<?php the_permalink() ?>'><?php the_title(); ?></a></li>
<li><p>by<span class="author"><?php the_author(); ?></span></p></li>


<?php endwhile; ?>
<?php endif; ?>
<?php wp_reset_query(); ?>

</ul>
</div>
</section>

<section class="cat-label-2">
<h2>Trending Stories</h2>
</section>

<section class="trending-categories">
<div class="cat-row">
<div class="cat-title">
<h4>Fashion</h4></div>

<?php query_posts( 'category_name=fashion&posts_per_page=1' ); ?>

<ul class="posts">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>

<li><a href="<?php the_permalink(); ?>"><?php the_post_thumbnail( array(220,220) ); ?></a></li>
<li><?php echo get_the_date('d.m.Y'); ?></li>
<li><a href='<?php the_permalink() ?>'><?php the_title(); ?></a></li>
<li><p>by<span class="author"><?php the_author(); ?></span></p></li>


<?php endwhile; ?>
<?php endif; ?>
<?php wp_reset_query(); ?>

</ul>
</div>

<div class="cat-row">
<div class="cat-title">
<h4>Travel</h4></div>

<?php query_posts( 'category_name=Travel&posts_per_page=1' ); ?>

<ul class="posts">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>

<li><a href="<?php the_permalink(); ?>"><?php the_post_thumbnail( array(220,220) ); ?></a></li>
<li><?php echo get_the_date('d.m.Y'); ?></li>
<li><a href='<?php the_permalink() ?>'><?php the_title(); ?></a></li>
<li><p>by<span class="author"><?php the_author(); ?></span></p></li>


<?php endwhile; ?>
<?php endif; ?>
<?php wp_reset_query(); ?>

</ul>
</div>

<div class="cat-row">
<div class="cat-title">
<h4>Interior</h4></div>

<?php query_posts( 'category_name=Travel&posts_per_page=1' ); ?>

<ul class="posts">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>

<li><a href="<?php the_permalink(); ?>"><?php the_post_thumbnail( array(220,220) ); ?></a></li>
<li><?php echo get_the_date('d.m.Y'); ?></li>
<li><a href='<?php the_permalink() ?>'><?php the_title(); ?></a></li>
<li><p>by<span class="author"><?php the_author(); ?></span></p></li>


<?php endwhile; ?>
<?php endif; ?>
<?php wp_reset_query(); ?>

</ul>
</div>

<div class="cat-row">
<div class="cat-title">
<h4>Work</h4></div>

<?php query_posts( 'category_name=Travel&posts_per_page=1' ); ?>

<ul class="posts">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>

<li><a href="<?php the_permalink(); ?>"><?php the_post_thumbnail( array(220,220) ); ?></a></li>
<li><?php echo get_the_date('d.m.Y'); ?></li>
<li><a href='<?php the_permalink() ?>'><?php the_title(); ?></a></li>
<li><p>by <span class="author"><?php the_author(); ?></span></p></li>


<?php endwhile; ?>
<?php endif; ?>
<?php wp_reset_query(); ?>

</ul>
</div>
</section>

<?php get_footer(); ?>

Screenshot

最佳答案

你不止一次打开两个div就像这样

<div class="cat-row">
<div class="cat-title">

带有 <ul>以下包含 li使用 PHP 循环加载的元素。

但后来,收盘后</ul>标签,你只有 一个 关闭</div>标签,其中最有可能应该有两个。

关于php - 循环后关闭div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50155374/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com