首页 > 解决方案 > 为什么我的 div 在 WP 模板中嵌套?

问题描述

我为 wordpress 网站创建了一个模板,我的 div 正在嵌套。该代码在我的codepen中运行,但是当我使用自定义帖子类型运行它时,它会嵌套它们。我读过它有时是因为打开的 div,这是有道理的,但我没有看到任何东西。有没有人经历过这个或看到任何问题?

<?php
get_header();
//the_content();
$args = array(
    'post_type'   => 'patterns'
);
$patterns = new WP_Query( $args );
if ( $patterns->have_posts() ) : ?>
        <?php while( $patterns->have_posts() ) : $patterns->the_post() ?>
            <div class="image_hover_appear <?php $categories = get_the_category( $patterns->ID, 'category' );
                foreach( $categories as $category ) {
                    echo $category->slug . ' ';
                } ?>">
                <div class="appear_container">
                    <img src="https://via.placeholder.com/300" alt="<?php the_title(); ?>">
                    <div class="appear_content">
                        <div class="appear_title">
                            <?php the_title(); ?>
                        </div>
                        <div class="appear_desc">
                            <!--This is the description-->
                        </div>
                    </div>
                    <a href="https://via.placeholder.com/300" class="appear_link" data-fancybox ></a>
                    <div class="appear_overlay"></div>
                    <div class="appear_border-top"></div>
                    <div class="appear_border-bottom"></div>
                </div>
            </div>
        <?php endwhile ?>
<?php endif ?>
<?php get_footer(); ?>

标签: phphtmlwordpress

解决方案


问题在于 astra 主题和我的孩子主题。我将自定义模板的代码添加到 archive.php 文件中,最后改变了布局。问题并不像看起来那样。


推荐阅读