开发者

Recursive query to display pages hierarchically (including their content)

开发者 https://www.devze.com 2023-03-23 12:21 出处:网络
I try to achieve the following layout with Wordpress 3.2.1: ---> ID 4 (Record 2, 3rd Attempt) --> ID 3 (Record 2, 2nd Attempt)

I try to achieve the following layout with Wordpress 3.2.1:

---> ID 4 (Record 2, 3rd Attempt)
 --> ID 3 (Record 2, 2nd Attempt)
  -> ID 2 (Record 2, 1st Attempt)
 --> ID 5 (Record 1, 2nd Attempt)
  -> ID 1 (Record 1, 1st Attempt)

Every line represents a page and on the Backend the page hierarchy looks like that:

-> ID 1
--> ID 5
-> ID 2
--> ID 3
---> ID 4

I'm sorry I prepared a nice illustration but I'm not yet allowed to post images. So, to explain it a bit further: I try to build a list of records and as soon as one of the records gets broken, it will shift to the right and on top of it the newest record attempt appears.

Ok, so first question: How do I have to set up query_posts to recursively get all children? The following code only returns page 3 but not 4:

<?php query_posts(ar开发者_运维问答ray('post_parent' => 2, 'post_type' => 'page')); ?>

And second question: Does anyone know a better/simpler/sexier (Wordpress) solution for what I try to achieve?


try

$child_pages = get_pages('child_of=2');

you can look it up in the WP Codex here: http://codex.wordpress.org/Function_Reference/get_pages

0

精彩评论

暂无评论...
验证码 换一张
取 消