How to list a page tree?

wp_list_pages will output all of the pages, posts, and CPTs that you wish. You even have control over the CSS classes, some of which are already there: All list items (li) generated by wp_list_pages() are marked with the class page_item. When wp_list_pages() is called while displaying a Page, the list item for that Page is … Read more

Redirect page to default subpage

You can try something like this. This will check if a page has child pages and if it does then it will redirect the first page in array ordered by menu order. // get child pages $child_page = get_pages( “child_of=” . $post->ID . “&sort_column=menu_order” ); if ( $child_page ) { // get id of first … Read more

Get Top parent url

You have to do it in a loop: $p = $post; while ( $p->post_parent ) { $p = get_post( $p->post_parent ); } $parent_page_link = get_permalink( $p->ID ); Another way is to use get_ancestors function: $ancestors = get_ancestors( $post->ID, ‘page’, ‘post_type’ ); $root = ( ! empty( $ancestors ) ) ? end($ancestors) : $post->ID; $parent_page_link = … Read more

Can a user find a child page?

This is a shortcode you see there in the post/page content. It’s most likely displaying all the child pages (up to depth 1) of the current page. Shortcodes are very common, but you can’t see their output in the WordPress post/page editor, only on the front end where it’s generated via the do_shortcode() function. The … Read more

is_child() function

/** * Return whether the current page is a child of $id * * Note: this function must be run after the `wp` hook. * Otherwise, the WP_Post object is not set up, and * is_page() will return false. * * @param int $id The post ID of the parent page * @return bool Whether … Read more

get_the_title() gets printed out twice

Your conditional is always true. To understand why, consider what happens in this function when there is no post parent: function get_top_ancestor_id() { global $post; // no parent so this doesn’t run: // if($post->post_parent) { // $ancestors = array_reverse(get_post_ancestors($post->ID)); // return $ancestors[0]; // } return $post->ID; } Which simplifies to: function get_top_ancestor_id() { global $post; … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)