Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am trying to use the $post object from functions.php in my theme however if I attempt to var_dump($post) it returns NULL.

Here is my code:

function breadcrumb_navigation() {
    var_dump($post);
    $page = $post;
    $parents = array();
    while ($page->post_parent){
        array_push($parents, $page);
        $page = $page->post_parent;
    }
    if (sizeof($parents) > 0) {
        array_reverse($parents);
        foreach($parents as $parent) {
            echo '<li><a href="'.get_permalink($parent->ID).'">'.$parent->post_title.'</a><ul class="child">', wp_list_pages(array('child_of' => $post->post_parent,'exclude' => $post->ID)), '</ul></li>';
        }
    }
}

Can anyone tell why this would be happening?

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

Call in global $post; at the top of the function.

share|improve this answer
    
That was simple :P –  George Reith Apr 13 '12 at 15:27
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.