WordPress.org

Ready to get started?Download WordPress

Forums

limit number of pages shown from of wp_list_pages, and a read more link (5 posts)

  1. rocketlures
    Member
    Posted 5 years ago #

    Is there any plugin that can shorten the listing of pages to the top few (say 5), and show a "more" link to go to another subpage to show the complete listing?

  2. wp_guy
    Member
    Posted 5 years ago #

    Don't know if there is a plugin for that but, you could do that by getting the pages, converting that to an array and then echo the first 5:

    <?php
    $howmany = 5;
    
    $pages = wp_list_pages("echo=0&title_li=");
    
    $pages_arr = explode("\n", $pages);
    
    for($i=0;$i<$howmany;$i++){
    	echo $pages_arr[$i];
    }
    
    ?>

    Then put a link to a page that lists them all... kinda like:

    <li><a href="url.to/page">More...</a></li>

    Hope that helps

  3. rocketlures
    Member
    Posted 5 years ago #

    Thank you, Wp_guy....most helpful :)

  4. bilibou
    Member
    Posted 5 years ago #

    Hi,

    Thank you wp_guy for this very useful tip.

    I would like to do something like:
    - list the first five child pages
    - create a new page (like nextpage quicktag do)
    - list the next five child pages
    - create a new page
    ....

    Thanks for your help

  5. electrifried
    Member
    Posted 5 years ago #

    WP-GUY you are srsly a legend. I've been wondering how to do this for AGES now and you just saved me from stuffing up my code so THANKYOU!:D:D:D

Topic Closed

This topic has been closed to new replies.

About this Topic