Support » Themes and Templates » Object unavailable inside content.php

  • Resolved JonathanMH

    (@jonathanmh_com)


    I have a class in my themes function.php. Calling methods of the created object works fine in index.php, but not in content.php.

    The error I get:
    Fatal error: Call to a member function post_thumbnail() on a non-object in [path of file]

    var_dump for my object in index.php:
    object(Ancestor)#168 (0) { }

    var_dump for my object in content.php:
    NULL

    My thought is, that is has something to do with http://codex.wordpress.org/Function_Reference/get_template_part

    How can I work around this?

Viewing 2 replies - 1 through 2 (of 2 total)
  • JonathanMH

    (@jonathanmh_com)

    Just tested, using:
    require_once( 'content.php' . get_post_format() );
    works and makes the object available. Now I just need to build a fallback, if a file isn’t there.

    Kind of weird, that it works this way and not the other though.

    JonathanMH

    (@jonathanmh_com)

    Aha! <?php global $object_name; ?> in the top of every file works!

    via:

    applying oop to wordpress themes

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Object unavailable inside content.php’ is closed to new replies.