0
$args = array(
    'post_type'      => 'page',
    'posts_per_page' => -1,
    'post_parent'    => $post->ID,
    'order'          => 'ASC',
    'orderby'        => 'menu_order'
 );


$parent = new WP_Query( $args );


if ( $parent->have_posts() ) : ?>

    <?php while ( $parent->have_posts() ) : $parent->the_post(); ?>
            <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a>
    <?php endwhile; ?>

<?php endif; wp_reset_postdata(); ?>

Как сделать условие если нету дочерных страниц выполнить другой запрос $args для того чтобь вывести соседные страницы а не дочерные

1 ответ 1

0
$args = array(
    'post_type'      => 'page',
    'posts_per_page' => -1,
    'post_parent'    => $post->ID,
    'order'          => 'ASC',
    'orderby'        => 'menu_order'
);


$child = new WP_Query( $args );


if ( $child->have_posts() ) : ?>

    <?php while ( $child->have_posts() ) : $child->the_post(); ?>
            <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a>
    <?php endwhile; ?>

<?php else: 

    $args = array(
        'post_type'      => 'page',
        'posts_per_page' => -1,
        'post_parent'    => $post->parent_id,
        'order'          => 'ASC',
        'orderby'        => 'menu_order'
    );


    $neighbors = new WP_Query( $args );

    ......

endif;

wp_reset_postdata(); ?>

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.