I've asked a question about listing all sub-pages before:
But all the questions were wrong.
Anyways, I have now simpler question.
global $post;
echo $post>ID
Works totally fine, but while on pages sidebars only. When it's next to the blog loop (in a blog section) it goes crazy, for example Blog has ID of 216 (and $post>ID in loop.php shows 216), but the $post>ID in the sidebar shows 87. Why is this happening? How to fix that?
Thank you!
[edit]
I have a suspicion that loop and sidebar are both included in index page separately and loop is getting different post ID than sidebar. The big question is how to change that.
[edit for Rarst]
wp_reset_postdata();
global $post;
$children = wp_list_pages('title_li=&child_of='.$post->ID.'&echo=0');
echo $children;
Gives the same result. It works with pages, not blog. I have a normal loop, as like in Twenty Ten for example.
query_posts
to perform other queries somewhere between when the main loop occurs and when the sidebar gets output,$wp_query->post
should hold an object of the first post(or page/custom type) from the main query, you could use that to determine ID, eg.$wp_query->post->ID
.