I am having a custom query that calls in pages in an array like so:

<?php
$args = array(
    'post__in' => array( 2, 7, 9, 11, 13 , 15, 17 ),
    'post_type' => 'page',
    'orderby' => 'menu_order',
    'order' => 'ASC'
);
$the_query = new WP_Query( $args ); 
while ( $the_query->have_posts() ) : $the_query->the_post();
?>

Is it still possible to target single pages of the array to have page specific alterations of the code, i.e.

<?php if(is_page(7)) { ?>
    // do something
<?php } else { ?>
    // do something else
<?php } ?>

inside this query or do I have to query every page in a a separate query?

I am using this query to put together multiple pages into one template (front-page.php) in order to have a onepaged layout, i.e. all content on one page, so I would like to use conditions inside the loop for clarity in my code.

1 Answer
1

You would rather want to use the post ID inside the loop to target your pages. is_page() simply checks whether the current page is actually a page or a specific page if a value is passed

Example

if ( $post->ID === 7 ) {
    // Do something for page id 7
} else {
    // Do something for other pages
}

Leave a Reply

Your email address will not be published. Required fields are marked *