I have a page structure like this:
-Home
-Cars
-Volvo 640
- Pics
- Info
-Porsche 911
- Pics
- Info
I’d like to generate a list of cars on the Cars page of all the cars (which are child pages of Cars). How would I do this? The list is basically a sub-menu which should show all the cars in alphabetical order (note, I don’t need links to the ‘grandchildren’ – Pics, Info). I also need to grab Custom Field data from each car page, and put that beside the link to the page.. is that possible?
You could use
get_pages
to do this, like so:Once you get to here, you can pull out your custom fields and put them into variables.
I would use an
if
statement of some kind to build those top headings. For instance you could do:It’s rough, but I think this could get you quite a long ways. Essentially, you’re programmatically building your headings and returning everything to get printed. The key is formatting everything and getting your conditions set up right.
The
wp_list_pages()
function can give you a list of your child pages. Grabbing custom field data from each page, though, would require a separate query and a bit more work. But here’s a start:This will give you a list of links to all of the child pages of page ID 123. The
depth
specification is to prevent retrieving grandchild pages as well.Like I said before, though, getting the custom field data is a bit trickier. You’ll need to first get the page ID of each of your child pages (probably using
query_posts()
) and store them in an array. Then you’ll loop through that array and get the custom field data from each page in turn.So it’s doable … but I can’t offer a quick solution off the top of my head.