简体   繁体   English

WordPress主题开发

[英]Wordpress Theme Development

what i'm currently trying to achieve is some simple theme options. 我目前正在尝试实现的是一些简单的主题选项。 What i want to b able todo is; 我想做的是

Under the Wordpress GUI, Theme options section which i've currently got a few setup (with no actions behind them), is to simply "Click a check box which will disable front page widgets, if it's on then show them if it's off disable them" 在Wordpress GUI下,我目前已进行了一些设置(没有任何操作)的“主题选项”部分是简单地“单击一个复选框,它将禁用首页小部件(如果已启用),然后显示它们,如果已禁用则禁用”。他们”

I understand the logic behind, but i have no idea on how to create something will will return a simple true of false, from the theme-options.php, link it into the front-page.php and use the result from theme-options to be the condition to show said area. 我了解背后的逻辑,但是我不知道如何创建某些东西,将返回一个true的false值,该值来自theme-options.php,将其链接到front-page.php中,并使用theme-options的结果作为显示该区域的条件。

Any help with this would be amazing. 任何帮助都将是惊人的。

<?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;
}

Also in the front-page.php I've required_once for this file, tried calling by doing: 同样在front-page.php中,我需要此文件,需要这样做:

echo theme_options_validate( $input['option1' );

however all i get is the word Array returned. 但是,我得到的只是返回的单词Array。

Regards, Ben 问候,本

Maybe that's because you made a typo. 也许是因为您打错了字。

You didn't close the bracket 您没有合上支架

echo theme_options_validate( $input['option1' );

Should be: 应该:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM