Checkbox in theme options

Asked

Viewed 81 times

1

I’m creating a options page for my theme in Wordpress, but I am with a certain difficulty related to checkbox.

The idea is as follows: If the checkbox infra_bloco1_visivel is marked it will enable a div page content. If unchecked, nothing appears.

In the options page the checkbox is like this:

$options[] = array(
    'name' => __('Bloco 1', 'options_check'),
    'desc' => __('Visível', 'options_check'),
    'id' => 'infra_bloco1_visivel',
    'std' => '1',
    'type' => 'checkbox');

The logic will be something like "If 'infra_block' is visible checked, show such DIV (or anything else) if you are not checked show nothing.

1 answer

1

Actually your solution is in a client-side language, in this case javascript, follows a solution that would solve

http://jsfiddle.net/deFreitas/wsc7sot4/1/

<input type="checkbox" class="checkbox" checked="checked" />Marque para mostrar ou ocultar
<br />
<div class="conteudo">conteudo a ser mostrado</div>

<script>
    function mostrarOcultar(){
        if($(".checkbox").prop("checked"))
            $(".conteudo").show();
        else 
            $(".conteudo").hide();
    }

    $(function(){
        mostrarOcultar();
        $(".checkbox").click(mostrarOcultar);
    })

</script>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.