0

I already check if the secondary page has sister pages and I show it in a list of sister pages within each secondary page, but when I am inside a sister page, in the list where I show it I want to make the page where it is located be marked.

Something like this:

Science books
  Book 1 
  Book 2
  Book 3

When I'm inside:

Book 2

In the list of books I want to mark the current page

Book 1
Aqual page: Book 2
Book 3

Is it possible? Thank you in advance


EDIT: I currently display the list of sibling pages within each sub-page as follows:

<?php
    global $post; 
    if ( $post->post_parent ) {  
        $siblings = new WP_Query( array(
            'post_type' => 'page',
            'order' => 'ASC',
            'post_parent' => $post->post_parent,
            'post__not_in' => array( $post->ID )
        ) );
    }

    if ( $siblings->have_posts() ) :
?>
    <ul>
        <?php while ( $siblings->have_posts() ) : $siblings->the_post(); ?>
        <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
        <?php endwhile; wp_reset_postdata(); ?>
    </ul>
<?php endif; ?>

1 Answer 1

1

Yes, it is possible:

<?php
    global $post;
    $current_post = $post;
    if ( $post->post_parent ) {  
        $siblings = new WP_Query( array(
            'post_type' => 'page',
            'order' => 'ASC',
            'post_parent' => $post->post_parent
        ) );
    }

    if ( $siblings->have_posts() ) :
?>
    <ul>
        <?php while ( $siblings->have_posts() ) : $siblings->the_post(); ?>
        <li><a href="<?php the_permalink(); ?>">
            <?php if ( $current_post->ID == $post->ID ) echo 'Actual page: '; ?>
            <?php the_title(); ?>
        </a></li>
        <?php endwhile; wp_reset_postdata(); ?>
    </ul>
<?php endif; ?>
3
  • I have tried the code in what I have right now but it doesn't show me anything, I may not have added it in the right place. I just edited the question, I added how I currently display the list of sibling pages within each sub-page. I added the code you provided me with inside: if ( $siblings->have_posts() ) { // Here } Commented Jun 14, 2018 at 10:33
  • I've updated my answer using your code. Commented Jun 14, 2018 at 10:40
  • It was for some nonsense that didn't work, thank you so much for your help! Commented Jun 14, 2018 at 11:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.