【问题标题】:Wordpress Theme DevelopmentWordPress 主题开发
【发布时间】:2017-05-04 18:01:44
【问题描述】:

我目前想要实现的是一些简单的主题选项。我想要做的是;

在 Wordpress GUI 下,我目前进行了一些设置(后面没有任何操作)的主题选项部分是简单地“单击一个复选框,它将禁用首页小部件,如果它打开则显示它们如果它关闭禁用它们”

我理解背后的逻辑,但我不知道如何创建一些东西会返回一个简单的真假,从theme-options.php,将它链接到front-page.php并使用来自的结果主题选项作为显示所述区域的条件。

对此的任何帮助都会令人惊叹。

<?php $options = get_option( 'SV_theme_options' ); ?>

<input id="SV_theme_options[option1]" name="SV_theme_options[option1]" type="checkbox" value="1" <?php checked( '1', $options['option1'] ); ?> />


/**
 * Sanitize and validate input. Accepts an array, return a sanitized array.
 */
function theme_options_validate( $input ) {
    global $select_options, $radio_options;

    // Our checkbox value is either 0 or 1
    if ( ! isset( $input['option1'] ) )
        $input['option1'] = null;
    $input['option1'] = ( $input['option1'] == 1 ? 1 : 0 );

    // Say our text option must be safe text with no HTML tags
    $input['sometext'] = wp_filter_nohtml_kses( $input['sometext'] );

    // Our select option must actually be in our array of select options
    if ( ! array_key_exists( $input['selectinput'], $select_options ) )
        $input['selectinput'] = null;

    // Our radio option must actually be in our array of radio options
    if ( ! isset( $input['radioinput'] ) )
        $input['radioinput'] = null;
    if ( ! array_key_exists( $input['radioinput'], $radio_options ) )
        $input['radioinput'] = null;

    // Say our textarea option must be safe text with the allowed tags for posts
    $input['sometextarea'] = wp_filter_post_kses( $input['sometextarea'] );

    return $input;
}

同样在 front-page.php 中,我已经为这个文件设置了 required_once,尝试通过以下方式调用:

echo theme_options_validate( $input['option1' );

但是我得到的只是返回的单词 Array。

问候, 本

【问题讨论】:

    标签: php wordpress


    【解决方案1】:

    可能是因为你打错字了。

    你没有关闭括号

    echo theme_options_validate( $input['option1' );
    

    应该是:

    echo theme_options_validate( $input['option1'] );
    

    【讨论】:

    • 啊抱歉,这只是我的错字,我已经包含了整个内容。我想要的只是 1 或 0 的结果,这样我就可以使用该条件来显示小部件等...
    猜你喜欢
    • 2016-10-12
    • 2016-02-24
    • 2015-07-14
    • 1970-01-01
    • 2012-10-23
    • 2012-10-11
    • 1970-01-01
    • 1970-01-01
    • 2014-11-18
    相关资源
    最近更新 更多