• Hi,

    I have been searching and reading documents but cannot find a way to limit the result to only show all the child pages of a parent page.

    Sometimes the content is static which will fit more in pages than post types. But the plugin lacks the flexibility for filtering pages. How can I achieve this goal via the OTHER ATTRIBUTES field or is there any other way to do it?

    I.e. I have a parent page for fruit example.com/fruit and I list all fruits as child pages like example.com/fruit/apple, example.com/fruit/grape. I want to show related fruit only via shortcoe or gutenberg block.

    Thanks

Viewing 1 replies (of 1 total)
  • You might not need to use CRP for that. Try this and adapt as you like. This one will list parent page and then the child pages as list items <li></li>:

    if (is_page()) {
                        $page_id = get_queried_object_id();
                        $parent_id = wp_get_post_parent_id($page_id);
                        $child_args = array(
                            'child_of' => $parent_id,
                            'title_li' => __(''),
                            'echo'     => 0,
                        );
    
                        if ($parent_id) {
                            // this is a child page
                            $child_pages = wp_list_pages($child_args);
                            $parent_page = get_page($parent_id);
                            echo '<li class="page_item_has_children current_page_ancestor current_page_parent page_item page-item-' . $parent_id . '"><a href="' . get_page_link($parent_page) . '" >' . $parent_page->post_title . '</a><li>';
                        } else {
                            // this is a parent page, homepage or special page
                            $child_args['child_of'] = $page_id;
                            $child_pages = wp_list_pages($child_args);
                            $parent_page = get_page($page_id);
                            echo '<li class="page_item_has_children current_page_item page_item page-item-' . $page_id . '"><a href="' . get_page_link($parent_page) . '" >' . $parent_page->post_title . '</a><li>';
                        }
                        echo $child_pages; 
                    }
Viewing 1 replies (of 1 total)
  • The topic ‘Show related child pages of a parent page’ is closed to new replies.