Wordpress 嵌套循环打印错误的 de html 代码


Wordpress nested loop prints wrong de html code

我在wordpress中的嵌套循环有问题,我的代码正在打印html元素,这是我的代码:

<div id="content">
    <div class="page-content">
        <ul class="menu-children">
        <?php
        $children_args = array(
            'post_type'      => 'page',
            'posts_per_page' => -1,
            'post_parent'       => $actual_page_ID,                               
            'order'             => 'ASC',
            'orderby'           => 'date',
        );
        $children = new WP_Query($children_args);
        //var_dump($children);
        if ( $children->have_posts() ) : ?>
            <?php while ( $children->have_posts() ) : $children->the_post(); ?>

            <a class="menu-child" href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
                <li class="menu-child-li">
                    <?php the_title(); ?>
                    <?php
                    //I get the title of the child page because is the name of the category i want to retrieve
                    $the_post_title=get_the_title();
                    $products_args = array(
                        'post_type' => 'alquiladora_product',
                        'category_name' => $the_post_title
                    );
                    $products = new WP_Query($products_args);
                    if ( $products->have_posts() ) : ?>
                    <ul class="sub-menu-child">
                        <?php while ( $products->have_posts() ) : $products->the_post(); ?>
                        <a class="menu-child sub-menu-child-a" href="<?php the_permalink(); ?>">
                            <li class="menu-child-li sub-menu-child-li">
                                <?php the_title(); ?>
                            </li>
                        </a>
                        <?php endwhile; ?>
                    <?php endif; wp_reset_query(); ?>
                    </ul>
                </li>
            </a>
            <?php endwhile; ?>
        <?php endif; wp_reset_query(); ?>
        </ul>
        <script>
        $(document).ready(function(){
            /* navigation sub-menu display */
            $('ul.sub-menu-child').parent().hover(function(){
                $(this).children('.sub-menu-child').slideToggle(300);
            });
        /* end navigation menu */
        });
        </script>
    </div>
</div>

如果类别名称与页面子标题匹配,则应该在 ul 内打印 ul,我有 2 个示例:在此页面中,它工作正常:http://mginteractive.com.mx/alquiladora/productos-para-eventos/

但在这个没有:http://mginteractive.com.mx/alquiladora/productos-de-construccion/

在检查第二个示例中的元素后,显示代码仅打印 -ul- 内的第一个 -li- 元素,将其他 -li- 元素打印出 -ul- 容器。我在循环中做错了什么?或如何修复它?

                if ( $products->have_posts() ) : ?>
                <ul class="sub-menu-child">
                <?php endif; wp_reset_query(); ?>
                </ul>

开盘<ul class="sub-menu-child">是有条件的,结束</ul>不是,这会导致输出类似

<ul class="menu-children">

            <a class="menu-child" href="http://mginteractive.com.mx/alquiladora/productos-de-construccion/modulos/" title="Módulos">
                <li class="menu-child-li">
                    Módulos                                     </ul>
                </li>
            </a>

看到莫杜洛斯之后的</ul>了吗?莫杜洛斯没有帖子,因此"sub-ul"尚未打开,但已关闭......外<ul>.