【问题标题】:WordPress Custom Widget - Template Tags Output in Wrong PlaceWordPress 自定义小部件 - 模板标签输出位置错误
【发布时间】:2011-08-24 11:26:04
【问题描述】:

我正在尝试编写一个简单的自定义小部件,允许用户注册特别优惠。因此,对于我的表单的“操作”,我希望它读取 action=" bloginfo('template_directory') . '/theme/php/handler.php'" 但每次我引用 bloginfo 标记时,输出都会被抛出<li> 用于小部件。

示例位于http://shineaz.com - 底部右侧边栏。

这是我的函数小部件():

function widget($args, $instance) {
    // outputs the content of the widget
    extract( $args, EXTR_SKIP);
    $args['title'] = isset($instance['title']) ? $instance['title'] : 'Sign up for Special Offers';

    echo $before_widget;
    echo $before_title . $args['title'] . $after_title;
    echo '<form id="special_offers" method="post" action="' . bloginfo('template_directory') . '/custom/php/special-offer-handler.php">
        </form>';
    echo $after_widget;
}

谢谢

【问题讨论】:

    标签: wordpress


    【解决方案1】:

    您应该更改它以返回值,而不是 echo:

    function widget($args, $instance) {
    // outputs the content of the widget
    extract( $args, EXTR_SKIP);
    $args['title'] = isset($instance['title']) ? $instance['title'] : 'Sign up for Special Offers';
    
    return $before_widget;
    return $before_title . $args['title'] . $after_title;
    return '<form id="special_offers" method="post" action="' . bloginfo('template_directory') . '/custom/php/special-offer-handler.php">
        </form>';
    return $after_widget;
    }
    

    然后使用echo widget(); 在模板中回显小部件

    【讨论】:

    • 在这种情况下,只有第一个return 会起作用,因为它会结束函数的执行。您必须连接这些值,然后只返回 this 的结果。
    猜你喜欢
    • 1970-01-01
    • 2018-03-14
    • 2017-10-31
    • 1970-01-01
    • 2019-07-03
    • 1970-01-01
    • 2015-01-20
    • 2011-09-16
    • 2021-07-11
    相关资源
    最近更新 更多