I'm building a WordPress options panel based on this tutorial: net.tutsplus.com/tutorials/wordpress/how-to-create-a-better-wordpress-options-panel/
One of the things I want to do is allow users to hide/display things based on their selection of Yes or No in the options panel. Specifically, I'm looking for some kind of output from the yes/no option that would do the following:
- When Yes is selected, it displays whatever I have between the code.
- When No is selected it simply doesn't call it (or hides it).
Currently, I use an array that looks like this for the Yes/No option in the options panel:
array( "name" => "Display breadcrumbs on post pages?",
"desc" => "Choose whether or not to display breadcrumbs, that is, the post trail.",
"id" => $shortname."_breadcrumbs",
"type" => "select",
"options" => array("Yes", "No"),
"std" => "Yes"),
Generally, this would call the output:
<?php echo get_option('to_breadcrumbs'); ?>
But I am using another code to call up breadcrumbs for my pages, which I want users to be able to show or hide:
<?php if (function_exists('dimox_breadcrumbs')) dimox_breadcrumbs(); ?>
So my preferred code would look like this:
SOME PIECE OF CODE
<?php if (function_exists('dimox_breadcrumbs')) dimox_breadcrumbs(); ?>
END NEW CODE
Figure it out, give me instructions, and the money is yours!
rizaljohn answers:
You can try this code:
if ( get_option('to_breadcrumbs') == 'Yes' ) {
if (function_exists('dimox_breadcrumbs')) dimox_breadcrumbs();
}
OR
You could do like this:
$breadcrumb_options = get_option('to_breadcrumbs');
if ( $breadcrumb_options['options'] == 'Yes' ) {
if (function_exists('dimox_breadcrumbs')) dimox_breadcrumbs();
}
Hope that helps.
Lucas Wynne comments:
Is there a way to setup the code so that if it is set to "No" a div class called "hide" is added? (Then, of course, I would make that class have have a display value of hidden)
rizaljohn comments:
$breadcrumb_options = get_option('to_breadcrumbs');
$show_hide = ($breadcrumb_options['options'] == 'Yes') ? 'show_breadcrumb': 'hide_breadcrumb';
if ( $breadcrumb_options['options'] == 'Yes' ) {
if (function_exists('dimox_breadcrumbs')) dimox_breadcrumbs();
}
Then in your div, you can have this:
<div class="<?php echo $show_hide; ?>">
Julio Potier answers:
Hello
How is used the array ? How can you know if the setting is Yes or No ?
Can you give me more code or admin acces to website ?
Thank you