WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Object unavailable inside content.php (3 posts)

  1. JonathanMH
    Member
    Posted 1 year ago #

    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?

  2. JonathanMH
    Member
    Posted 1 year ago #

    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.

  3. JonathanMH
    Member
    Posted 1 year ago #

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

    via:
    http://labs.earthpeople.se/2010/03/applying-oop-to-wordpress-themes/

Topic Closed

This topic has been closed to new replies.

About this Topic