• Resolved whateverfree2

    (@whateverfree2)


    Hi,
    I tried to add more content for archive page, here is my code

    <?php if (is_category()) {
    echo $pod->display('extra_content_for_category');
    }
    ?>

    I put this code in Genesis Simple Hooks at genesis_after_content position but I get this error
    Fatal error: Call to a member function display() on null in /home/mydomain.com/public_html/wp-content/plugins/genesis-simple-hooks/genesis-simple-hooks.php(184) : eval()'d code on line 2

    What does that mean?

    I am using Genesis framework and Simple Hooks plugin

    Thanks for your help!
    H

Viewing 13 replies - 1 through 13 (of 13 total)
  • Plugin Contributor Jim True

    (@jimtrue)

    That means you didn’t open a Pods object before attempting to display it, I believe.

    It looks like you’re also trying to do that through Genesis Simple Hooks which probably isn’t going to work the way you intend there.

    You don’t have a $pod created yet in that PHP above. You would actually need to do a $pod = pods('taxonomy'); first (or whatever your taxonomy is).

    Since it’s assumed (possibly?) that this portion of the hook/filter is within the loop, you should be able to do use get_term_meta() to get to your ‘extra_content_for_category’.

    Thread Starter whateverfree2

    (@whateverfree2)

    I tried

    <?php if (is_category()) {
    $pod = pods('taxonomy');
    echo $pod->display('extra_content_for_category');
    }
    ?>

    But it show blank page, the taxonomy is default WordPress category

    About get_term_meta, could you please help write the code to get ‘extra_content_for_category’?

    Thanks sir

    Plugin Contributor Scott Kingsley Clark

    (@sc0ttkclark)

    Jim meant “taxonomy” as in a placeholder for the name of your taxonomy. In this case you should use “category”.

    Plugin Contributor Jim True

    (@jimtrue)

    I did mention above you need to use “whatever your taxonomy is”, you can’t just use ‘taxonomy’ if you don’t have a registered taxonomy called ‘taxonomy’ or you’re going to get an error. So yep, I should’ve been clearer in my instructions, sorry!

    In your case, if you’ve added meta fields to ‘category’, it’s just ‘category’, so:

    
    $pod = pods('category');
    echo $pod=>display('extra_content_for_category');
    

    get_term_meta requires you to know the term_id that’s being passed and if you’re not comfortable with PHP, I’d keep this simple as possible.

    • This reply was modified 7 years, 11 months ago by Jim True.
    Thread Starter whateverfree2

    (@whateverfree2)

    Thanks Jim,

    I got an other error display

    Parse error: syntax error, unexpected '=>' (T_DOUBLE_ARROW), expecting ',' or ';' in /home/mydomain.com/public_html/wp-content/plugins/genesis-simple-hooks/genesis-simple-hooks.php(184) : eval()'d code on line 3

    Plugin Contributor Scott Kingsley Clark

    (@sc0ttkclark)

    That should be $pod->display With the -> instead of =>

    Thread Starter whateverfree2

    (@whateverfree2)

    OK
    the final code is

    <?php if (is_category()) {
    $pod = pods('category');
    echo $pod->display('extra_content_for_category');
    }
    ?>

    but nothing display, no error but nothing

    I am a customer of Genesis but they did not answer my question on the forum as well the question via ticket.

    Plugin Contributor Jim True

    (@jimtrue)

    Since you’re using the Genesis Simple Hooks plugin and it says it also allows shortcodes, try this:

    [pods name="category"]{@extra_content_for_category}[/pods]

    That’s essentially the same thing without the is_category check. It should only display something if you actually have something.

    My guess is you’re running into a “context area” issue. Either the place you’re putting the content isn’t the right place (you’re using the wrong hook), the hook is being hidden by your theme in this particular location by some other code or something else is wrong (ie that hook isn’t called on this particular archive).

    I’d love to help you find the right answers there for your theme, but honestly, I’ve always found Genesis support very unhelpful myself or I’m just not looking in the right place. I found a good site to look for answers, but he’s hiding all the answers behind a ‘members only’ content section, which isn’t helpful.

    You mostly need to validate that the hook you’re trying to add to is ran on the archive you’re outputting and that you have the right hook. If you do, then the shortcode above should work fine.

    Plugin Contributor Jim True

    (@jimtrue)

    Oh and my apologies on the code confusion with => instead of ->. I’m not really a PHP developer, either and often get confused between those two ‘arrow’ types ??

    Thread Starter whateverfree2

    (@whateverfree2)

    Thanks Jim very much for your help.
    The shortcode works very well, it can output the extra content now.

    However, the output display on all home page, single post, page and archive page.
    I need it display for archive page (category page) only.

    I’ve tried with code below but the output is blank.

    <?php if (is_category()) {
    do_shortcode('[pods name="category"]{@extra_content_for_category}[/pods]');
    }
    ?>

    Could you please checking my code if there is a mistake in it?

    Thanks Jim,

    Plugin Contributor Jim True

    (@jimtrue)

    I’m not a theme editor, we’ve confirmed that Pods isn’t the issue in this particular situation. At this point, you really do need to go to the Genesis support forums for assistance on solving this particular piece of the Genesis theme puzzle.

    As I mentioned above, it all is based on context and are you using the right hook, etc. And that’s theme specific, not Pods, sorry!

    Thread Starter whateverfree2

    (@whateverfree2)

    Thanks Jim for your help. I just sent a ticket to Studiopress to ask their support, will post the code here if it got fixed.

    Best regards,

    Plugin Contributor Jim True

    (@jimtrue)

    Sounds good! Thanks and good luck!

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘Fatal error: Call to a member function display() on null in’ is closed to new replies.