• Resolved uaioe

    (@uaioe)


    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.

Viewing 7 replies - 1 through 7 (of 7 total)
  • MichaelH

    (@michaelh)

    This should return the current page id:

    if (is_page( )) {
      $page = get_query_var('page_id');
    }

    Without commenting on the viability of the other code, I would think this line:
    $parent = get_post($post->post_parent);
    shoud be
    $parent = get_post('p='.$post->post_parent);

    Other examples at:
    wp_list_pages()
    query_posts()

    Thread Starter uaioe

    (@uaioe)

    Thanks MichaelH, I’ll give that a shot.

    Thread Starter uaioe

    (@uaioe)

    Well, that’s just returning 0.

    I don’t know if I’m explaining myself well. My posts page is located at mydomain.com/about-us/blog. For some reason, my sidebar won’t show Blog at in the list of pages under About Us. In fact, there is no sidebar showing up at all when you’re in the blog.

    Every other child of About Us shows a nicely formatted page list in the sidebar with the current page selected. Blog seems to act on its own rules, even though it is a page and a child of About us. Something about assigning mydomain.com/about-us/blog to be the Posts Page is screwing up the logic of the page list in the sidebar.

    I’m stumped.

    MichaelH

    (@michaelh)

    I am not having any problem creating a Blog page, creating a Child of Blog page, and designating Child of Blog as the “Posts page” under Settings->Reading.

    If I put this in my index.php:

    <?php
    if ( is_page() || $wp_query->is_posts_page ) {
    echo 'this is the posts page';
    }

    it displays “this is the posts page” when I access the Child of Blog page and it successfully displays my posts.

    Thread Starter uaioe

    (@uaioe)

    But it’s not the posts I’m having trouble showing, it’s showing the active Blog link in the sidebar.

    Example of structure of my sidebar (see the code above to see how I’m displaying the pages in the sidebar):

    About Us
    – Blog
    – Who we are
    – Biographies
    – Contact

    If I select “Who we are”, it’s shown as the active page in the sidebar. If I select “Blog”, the sidebar disappears entirely, even though it should be following the same logic as every other child of “About Us”.

    I think it has something to do with the fact that the logic changes somehow if a page becomes the posts page.

    MichaelH

    (@michaelh)

    If I select “Blog”, the sidebar disappears entirely, even though it should be following the same logic as every other child of “About Us”.

    Your theme’s index.php file is what displays the “Posts page”, regardless of what you put as the Template value on the “Blog” Page. So if your index.php doesn’t call for a sidebar that could be the problem.

    Please provide a link to see the problem if you continue this thread.

    Thread Starter uaioe

    (@uaioe)

    Actually, MichaelH, the wp_query function did seem to help. It’s not perfect, but it’s good enough to work for this particular site.

    Thanks for your help!

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Blog as a child (blog on a page)’ is closed to new replies.