Blog as a child (blog on a page)
-
Ok, first off, my apologies if this is a ridiculously stupid question. I’m not new to PHP but I am new to wordpress and I’m sure this is something that’s been figured out already, I just can’t find the solution after hours of searching.
I’m using a static page for my “Front Page” and a static page for my “Posts Page” via the handy control in the Reading Settings. I can see my posts and I can see my homepage and everything works fine there.
The thing is, my blog is a child of my “About Us” section. “About Us” is meant to contain: “Blog”,”Who We Are”,”Biographies”,and “Contact”. So, when I go to list the blog in the sidebar along with the other children and grandchildren of “About Us”, the $post->ID for the page seems to be overwritten by the ID for the blog posting. If my ancestor “About Us” section has an ID of 15, the ID is now becoming 1 (the first blog post) and my sidenav disappears.
Here’s the code I’m using, in case this is getting too confusingly verbose:
<?php if ($post->post_parent) { //if you're in a sub-page $parent = get_post($post->post_parent); if ($parent->post_parent) { //you're in a grandchild $children = wp_list_pages("title_li=&child_of=".$parent->post_parent."&echo=0&sort_column=menu_order"); } else { //you're on a child $children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0&sort_column=menu_order"); } } else { //if you're in the ancestor $children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0&sort_column=menu_order"); } if ($children) echo $children; ?>
I have a feeling I’m missing something simple, but at this point I’ve spent so much time thinking about it, I’m as confused as ever.
Thanks.
- The topic ‘Blog as a child (blog on a page)’ is closed to new replies.