WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] what does this line of code do? (6 posts)

  1. mzimmers
    Member
    Posted 6 years ago #

    Hi -

    I've read the docs on this, and I *think* I understand, but I want to be sure, because I'm basing some work on this.

    $thispage = $wp_query->post;

    Am I correct in my assumption that this is assigning the contents of a data structure (the current post) to a variable called $thispage?

    If I am correct, is there any documentation on the data structure for a post?

    Thanks.

  2. Scoop0901
    Member
    Posted 6 years ago #

  3. mzimmers
    Member
    Posted 6 years ago #

    I did read that section. It's helpful, but less than definitive. I have a section of code that isn't behaving as I think it should. This excerpt is supposed to list a page's parent (if one exists), the page itself, and any children of the page:

    $thispage = $wp_query->post;
    		if ($thispage->post_parent!=0)
            {
                wp_list_pages("title_li=Parent:&include=".$thispage->post_parent);
    			echo "this page's parent ID is " . $thispage->post_parent . $newline;
            }
    
    		wp_list_pages("title_li=ThisPage:&include=".$thispage->ID); 
    
    		echo "this page's ID is " . $thispage->ID . $newline;
    
            wp_list_pages("title_li=Children:&sort_column=menu_order&depth=2&child_of=".$thispage->ID); ?>

    But it's not working right. I thought if could see the internals of the post data structure, I could de-bug this a little easier. Any other suggestions?

  4. mzimmers
    Member
    Posted 6 years ago #

    Anyway...if someone could explain why that works for top-level pages and sub-pages, but NOT for sub-sub-pages, I would appreciate it greatly.

    http://www.scopedin.com/wordpress

  5. mzimmers
    Member
    Posted 6 years ago #

    A little more information: when I follow a link to a sub-sub-Page, my "echo" tells me that the wp_query is returning the correct parent page ID, and the ID of the sub-sub-page is correct as well. Yet...wp_list_pages isn't working for either.

    Any ideas? I could really use some help with this one.

    http://www.scopedin.com/wordpress

    Thanks.

  6. mzimmers
    Member
    Posted 6 years ago #

    OK...I think I'll close this thread out and create a new topic that is hopefully more focused.

Topic Closed

This topic has been closed to new replies.

About this Topic