将每个孩子及其孙子分开包裹起来

时间:2017-12-08 23:52:29

标签: php wordpress

我需要帮助分隔子页面,这就是我现在所拥有的:

<ul class="children">
    <li class="page_item page-item-54 page_item_has_children"><span>Title of Child1</span>
    <ul class="children">
        <li class="page_item page-item-60"><a>Grandchild1</a></li>
        <li class="page_item page-item-62"><a>Grandchild2</a></li>
    </ul>
</li>
    <li class="page_item page-item-58 page_item_has_children"><span>Title of Child2</span>
    <ul class="children">
        <li class="page_item page-item-64"><a>Grandchild1</a></li>
        <li class="page_item page-item-66"><a>Grandchild2</a></li>
    </ul>
</li>
</ul>

这就是我想要实现的目标: enter image description here

<div class="children-list">
    <ul class="children">
        <span>Title of Child1</span>
        <li class="page_item page-item-60"><a>Grandchild1</a></li>
        <li class="page_item page-item-62"><a>Grandchild2</a></li>
    </ul>

    <ul class="children">
        <span>Title of Child2</span>
        <li class="page_item page-item-64"><a>Grandchild1</a></li>
        <li class="page_item page-item-66"><a>Grandchild2</a></li>
    </ul>
</div>

这是我用于wp_list_pages

的助行器
class series_walker extends Walker_Page {
    public function start_el( &$output, $page, $depth = 0, $args = array(), $current_page = 0 ) {
        if ( isset( $args['item_spacing'] ) && 'preserve' === $args['item_spacing'] ) {
            $t = "\t";
            $n = "\n";
        } else {
            $t = '';
            $n = '';
        }
        if ( $depth ) {
            $indent = str_repeat( $t, $depth );
        } else {
            $indent = '';
        }

        $css_class = array( 'page_item', 'page-item-' . $page->ID );

        if ( isset( $args['pages_with_children'][ $page->ID ] ) ) {
            $css_class[] = 'page_item_has_children';
        }

        if ( ! empty( $current_page ) ) {
            $_current_page = get_post( $current_page );
            if ( $_current_page && in_array( $page->ID, $_current_page->ancestors ) ) {
                $css_class[] = 'current_page_ancestor';
            }
            if ( $page->ID == $current_page ) {
                $css_class[] = 'current_page_item';
            } elseif ( $_current_page && $page->ID == $_current_page->post_parent ) {
                $css_class[] = 'current_page_parent';
            }
        } elseif ( $page->ID == get_option('page_for_posts') ) {
            $css_class[] = 'current_page_parent';
        }

        $css_classes = implode( ' ', apply_filters( 'page_css_class', $css_class, $page, $depth, $args, $current_page ) );

        if ( '' === $page->post_title ) {
            /* translators: %d: ID of a post */
            $page->post_title = sprintf( __( '#%d (no title)' ), $page->ID );
        }

        $args['link_before'] = empty( $args['link_before'] ) ? '' : $args['link_before'];
        $args['link_after'] = empty( $args['link_after'] ) ? '' : $args['link_after'];

        $atts = array();
        $atts['href'] = get_permalink( $page->ID );

        $output .= $indent . sprintf(
            '<li class="%s">'.(($depth == 1) ? '<span%s>%s%s%s</span>' : '<a%s>%s%s%s</a>'),
            $css_classes,
            $attributes,
            $args['link_before'],
            /** This filter is documented in wp-includes/post-template.php */
            apply_filters( 'the_title', $page->post_title, $page->ID ),
            $args['link_after']
        );
    }

}

我完全卡住了。谁能指出我正确的方向?在哪里添加标记?要修改什么?

0 个答案:

没有答案