First or Last Page in Page-Structures of WordPress
Now and then little snippets are pretty useful. For a fix in a Premium-Theme, I needed a kind of evaluation, where I am in the site structure and with little effort I was able to expand the classes and react with CSS.
The following code shows the basic for it and get_pages()
is the key from the core of WordPress to get to these results. This function provides the necessary result of using the parameter and the output via the parameter sort_order
provides the sequence and identification of the first page, which is then either the first or last page in this structure.
// First post in structure // simple, but usefull global $post; $page_childs = get_pages( 'child_of=' . $post->post_parent . '&sort_order=ASC' ); $first_child = $page_childs[0]; if ( get_the_ID() === (int) $first_child->ID ) echo 'First Child';
// Last post in structure global $post; $page_childs = get_pages( 'child_of=' . $post->post_parent . '&sort_order=DESC' ); $last_child = $page_childs[0]; if ( get_the_ID() === (int) $last_child->ID ) echo 'Last Child';
© WP Engineer Team, All rights reserved (Digital Fingerprint: WPEngineer-be0254ce2b4972feb4b9cb72034a092d)