Jump to content

Recommended Posts

Posted

hi @ all.

how can i get a list/array of all pages (recursiv)

- but without admin-pages

- incluing all sub-pages?

pages i won't get:
for example:

Pages
Add Page
Page List
Save Sort
Edit Page
Templates
Fields
Modules
Setup
Access
Users
Roles
Permissions
Edit pages
Delete pages
Move pages (change parent)
View pages
Sort child pages
Change templates on pages
Administer users (role must also have template edit access)
User can update profile/password
Lock or unlock a page

thanks a lot and regards.

stefan

Posted

This turns out more complex than it seems, but it is usually something not used that often or ever at all. Even with my experience took some time to get all pages, unpublished , published, hidden, not in trash and not under admin. This is with superuser logged in as I think as editor or guest user you won't get pages from trash anyway.

But something like this is needed currently :) Unless I'm missing something.

$pa = $pages->find("has_parent!=2,id!=2|7,status<".Page::statusTrash.",include=all");

foreach ($pa as $p) {
  echo "<li>$p->path</li>";
} 

Note that as soon as you got a few hundred or thousand pages you will get a problem  ;)

Edit:

id = 2 // is the /processwire/ admin parent

id = 7 // is the trash

include=all // to get all pages unpublished and hidden

  • Like 5
Posted

Oh man... thanks a lot. I forgot - I was logged in as admin. damn!

thats great.

Your code works as admin, too!

Best Solution from Soma:
 

$result = $pages->find("has_parent!=2,id!=2|7,status<".Page::statusTrash.",include=all");

Thank you. Best regards


Stefan

  • Like 1
Posted

Another option that might work (though not yet tested to compare):

$result = $pages->find("template!=admin, has_parent!=2, include=all"); 
  • Like 4
  • 2 years later...
Posted

These are great snippets! 

But I got one more question: how to exclude sites that are unpublished?

By default, ProcessWire only returns published pages...so, exclusion of unpublished pages is already done within a 'find'

  • Like 1
Posted

@LostKobrakai: Thank you, works like a charm!

@kongondo: I want include hidden but published pages. With find, hidden pages are also excluded. 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...