WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] limit wp_list_pages (6 posts)

  1. peli
    Member
    Posted 7 years ago #

    How can I limit the list of pages?
    I am using: <?php wp_list_pages('title_li=&sort_column=post_date&sort_order=DESC'); ?>
    but I wolud like to list the only 25 newest pages, not the whole list.
    I can not use the include or the exclude arguments,
    because then I have to change it every day.

    Is there any solution?

  2. Bodhipaksa
    Member
    Posted 7 years ago #

    http://www.semiologic.com/2005/04/10/wordpress-recent-plugin-collection/

    "Recent updates displays a list of recently updated pages on your WordPress blog."

  3. rudolf45
    Member
    Posted 7 years ago #

    The bad thing is... pages and Pages are two different things in WP. And the OP was asking about Pages.
    (meanwhile the plugin author should make it clear: it is about posts!)

  4. yoshi
    Member
    Posted 7 years ago #

    The best way I think is to write a little function that does the similar job as wp_list_pages. However, here's an alternative way.

    <?php $pages = wp_list_pages('title_li=&sort_column=post_date&sort_order=DESC&depth=-1&echo=0');
    preg_match_all('/(<li.*?>)(.*?)<\/li>/i', $pages, $matches);
    if (!empty($matches[0])) {
      print '<ul>' . implode("\n", array_slice($matches[0],0,25)) . '</ul>';
    }
    ?>

    Note that this won't work if depth parameter set to other than -1 when there are child pages.

  5. Bodhipaksa
    Member
    Posted 7 years ago #

    "meanwhile the plugin author should make it clear: it is about posts!"

    Yes indeed! He had me fooled!

  6. peli
    Member
    Posted 7 years ago #

    it seems that the function works fine.

    thanks yoshi

Topic Closed

This topic has been closed to new replies.

About this Topic