Get Custom Field Values
Empty widget shows up (2 posts)

  1. Stefan
    Posted 4 years ago #

    Hi there,

    first thanks a lot for this plugin. It was exactly what I searched for.
    Although I still have one suggestion for making me 100% happy :-)

    I have some posts with custom-fields that should show up in the sidebar (e.g. see http://www.klaviernoten4u.de/river-flows-in-you/ the right top-widget is from the custom-field "sidebar")
    But I have other posts (currently all others :-) that doesn't have the custom-field "sidebar" defined and nothing should be displayed in the sidebar.
    The widget is therefore configured with
    Post-ID = 0
    Custom field key = sidebar

    Everything else is empty.

    Nevertheless even though there is nothing to be shown the widget shows up (it is displayed emtpy). The $before_widget and $after_widget is rendered and so you see an empty widget-box.

    My proposal would be this:
    In get-custom-field-values/get-custom.widget.php the method widget_body should return the result (and not echo it):

    function widget_body( $args, $settings, $instance ) {
    if ( 'current' == $post_id )
    return c2c_get_current_custom( $field, $before, $after, $none, $between, $before_last );
    elseif ...

    and in

    get-custom-field-values/c2c-widget.php in method widget (where widget_body is called) instead of

    echo $before_widget;

    if ( ! empty( $title ) )
    echo $before_title . $title . $after_title;

    $this->widget_body( $args, $instance, $settings );

    echo $after_widget;

    I would suggest these changes:

    $body = $this->widget_body( $args, $instance, $settings );

    if ( strlen( trim( $body) ) ) {
    echo $before_widget;
    if ( ! empty( $title ) )
    echo $before_title . $title . $after_title;
    echo $body . $after_widget;

    That avoids showing up empty widgets. And it avoids a title to be displayed if there is no body.

    Thanks again and hope it helps and wish this could be inserted in a future release.


  2. Scott Reilly
    WordPress & Plugin Dev
    Plugin Author

    Posted 4 years ago #

    Great suggestion! You can definitely expect to have this in v3.4 of the plugin, which should be out soon. Thanks!

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic