• Hello guys,

    I have a function that shows the titles of childpages of certain pages with shortcode.

    The problem is I have 18 childpages and he is showing me all.

    I would like to stay:
    childpag…
    childpag…
    childpag…
    childpag…
    childpag…

    I could limit the amount of titles and limit the number of characters.

    //Add a shortcode for listing child pages of a parent page
    function list_pages_shortcode( $atts ) {
        // Basic shortcode markup
        extract( shortcode_atts( array(
            'post_parent' => false,
            'title' => '',
        ), $atts ) );
    
        //If the post parent attribute isn't specified, use the current post's ID
        if ( ! $post_parent ) {
        global $post;
            if ( is_object( $post ) ) {
                $post_parent = $post->ID;
            } else {
                return false;
            }
        }
    
        //Build the arguments - we want the child of the post_parent
        $args = array(
            'depth'        => 3,
            'child_of'     => $post_parent,
            'title_li'     => $title,
            'echo'         => 0,
            'sort_column'  => 'menu_order, post_title'
            );
    
        // if there is no title lets barf up the wordpress pages instead
        if ( empty( $title ) ) {
            return "<ul>" . wp_list_pages( $args ) . "</ul>";
        } else {
            return wp_list_pages( $args );
        }
    }
    add_shortcode( 'list_subpages', 'list_pages_shortcode' );

    Thank you!

  • The topic ‘How Limit show Child Pages titles and characters?’ is closed to new replies.