Поддержка Проблемы и решения Дочерние страницы через шорткод

  • Решено vsezanyatouzhe

    (@vsezanyatouzhe)


    Добрый вечер.
    Есть функция, которую я подключаю в page.php

    function asd() {
    $childpages = new WP_Query( array(
    	'post_type'      => 'page',
    	'post_parent'    => $this_page,
    	'posts_per_page' => 100,
    	'orderby'        => 'menu_order',
    	'post__in' => array( 11 )
    ));
    	while ( $childpages->have_posts() ) : $childpages->the_post(); ?>
    
    	<section>
    
    		<a href="<?php echo get_page_link( $page->ID );?>"><?php the_title(); ?></a>
    			<div class="content">
    
    				<?php $this_subpage=$post->ID; ?>
    
    				<?php
    				//Loop through the sub-pages of the child pages next
    				$subpages = new WP_Query( array(
    					'post_type' => 'page',
    					'post_parent' => $this_subpage,
    					'posts_per_page' => 0,
    					'orderby' => 'menu_order',
    					'post_parent__in' => array(11)
    				));
    				while ( $subpages->have_posts() ) : $subpages->the_post(); ?>
    					<section class="subpages">
    
    						<a href="<?php echo get_page_link( $page->ID );?>"><?php the_title(); ?></a>
    						<div>
    
    						</div>
    					</section>
    				<?php endwhile; wp_reset_query(); ?>
    
    		</div><!--.content -->
    	</section>
    <?php endwhile; wp_reset_query(); }
     asd();?>

    Таким образом она выводит родительскую страницу и ее дочерние — выводит нормально.

    Е пытаюсь добавить ее через шорткод (не особо в этом) делаю так:

    function wp_p() {
    
    $childpages = new WP_Query( array(
    	'post_type'      => 'page',
    	'post_parent'    => $this_page,
    	'posts_per_page' => 100,
    	'orderby'        => 'menu_order',
    	'post__in' => array( 11 )
    ));
    	while ( $childpages->have_posts() ) : $childpages->the_post(); 
    
    	$string1 =  '<ul class="side-menu"><li><a href="'.get_page_link( $post->ID ).'">'.get_the_title().'</a></li>';
    
    				 $this_subpage=$post->ID; 
    
    				//Loop through the sub-pages of the child pages next
    				$subpages = new WP_Query( array(
    					'post_type' => 'page',
    					'post_parent' => $this_subpage,
    					'posts_per_page' => -1,
    					'order' => 'ASC',
    					'orderby' => 'date',
    					'post_parent__in' => array(11)
    				));
    				while ( $subpages->have_posts() ) : $subpages->the_post();
    
    					$string2 =  '<li><a href="'.get_page_link( $post->ID ).'">'.get_the_title().'</a></li></ul>';
    						return $string1.$string2;
    
    				endwhile; wp_reset_query();
    
     endwhile; wp_reset_query(); 
    
    }
    add_shortcode('lch', 'wp_p');

    Таким образом она выводит только родительскую страницу и одну дочернюю, на всех дочерних только одну последнюю добавленную (ну в таком варианте ‘order’ => ‘ASC’,
    ‘orderby’ => ‘date’,) первую добавленную

    Подскажите пожалуйста, что не так?

Просмотр 2 ответов — с 16 по 17 (всего 17)
Просмотр 2 ответов — с 16 по 17 (всего 17)
  • Тема «Дочерние страницы через шорткод» закрыта для новых ответов.