Function to add DIV Class?

时间:2011-09-28 作者:AndrettiMilas

我正在构建WordPress选项面板。

在我的选项面板中,我添加了以下内容,这将创建一个是/否下拉菜单,询问用户是否要显示面包屑-I want to be able to hide (or simply not call) the breadcrumbs when a user selects no:

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"),
通常,我会使用类似这样的方式调用上述函数:

<?php echo get_option(\'to_breadcrumbs\'); ?>
但是面包屑有自己的功能,我这样称呼它们:

<?php if (function_exists(\'dimox_breadcrumbs\')) dimox_breadcrumbs(); ?>

One possible solution that could be applied in other uses would be to add a div class with the hide property around the function I am calling when "No" is selected. Any help?

1 个回复
最合适的回答,由SO网友:Pat 整理而成

为什么不在打电话之前检查一下选项dimox_breadcrumbs() 像这样:

<?php
    // Check if the user wants breadcrumbs, default to "Yes" if no option set
    if(strcmp(get_option("to_breadcrumbs", "Yes"), "Yes") == 0){
         if (function_exists(\'dimox_breadcrumbs\')) {
             dimox_breadcrumbs();
         }
    }
?>

结束