PHP Code Widget
[resolved] Code String Not Executing Properly / User Error? (3 posts)

  1. Doctor Psyringe
    Posted 2 years ago #

    Ok, so I've been coding up loads of ads for my website to get that extra revenue edge. But I want my Authors to have the Ability to not only change the Ad Content, but Enable it and Disable it.

    So - for all of my custom post types and regular post types/pages - the following works in conjunction with my WordPress Editor User Interface;

    <?php if(!$oswc_widget_ad_hide) { ?>
    <table style="width: 300px;" border="0">
    <?php if ($widgetadvertisement) { ?>
    <?php echo $widgetadvertisement; ?>
    <?php } else { ?>
    <?php } ?>
    <td style="text-align: center;">
    <span style="font-size: xx-small;">Advertisement</span>
    <?php } ?>

    oswc_widget_ad_hide - Enable or Disable
    widgetadvertisement - The Content, with a Default if no is data provided.

    This code doesn't work in the widget. In fact, the same effect occurs then I plug that .php into a Unwrapped Text as this PHP Widget, so perhaps I already have .php enabled and the goal of this code should be resolved elsewhere. Nonetheless, it damages the template, moves the footer to the sidebar. Ok... so maybe that code is wrong for the purpose, being outside "the loop". Of course I coded a version using a variation of;

    <?php global $wp_query;
    if(is_object($wp_query->queried_object) && $wp_query->queried_object->ID)
    echo get_post_meta($wp_query->queried_object->ID, 'customfieldname', true);

    Not that I got that working either, if anything it damaged the code and turned the widget into a title line. By the way, saying there is a method to get this code working, is this widget available Unwrapped, surprised it's not available in that form.



  2. Doctor Psyringe
    Posted 2 years ago #

    After further research I'm fairly positive this is a user error demanding these variables must be declared Global then called, I'll report back after a hopefully swift resolution.

  3. Samuel Wood (Otto)
    WordPress.org Tech Dude
    Plugin Author

    Posted 2 years ago #

    Yep. Globals will get you if you're not careful. Code in the widget does not run in the global context.


Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic


No tags yet.