Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
是我的PHP条件逻辑不正确还是我犯了一些愚蠢的错误_Php_Wordpress - Fatal编程技术网

是我的PHP条件逻辑不正确还是我犯了一些愚蠢的错误

是我的PHP条件逻辑不正确还是我犯了一些愚蠢的错误,php,wordpress,Php,Wordpress,这个逻辑是一个PHP逻辑,但是有一个用于post元数据的wordpress函数→ <?php // U need to use this to set the checked="checked" $checkbox_value = get_post_meta($object->ID, "meta-box-radio", true); ?> <l

这个逻辑是一个PHP逻辑,但是有一个用于post元数据的wordpress函数→

 <?php
               // U need to use this to set the checked="checked"
               $checkbox_value = get_post_meta($object->ID, "meta-box-radio", true);
           ?>
                      <label>
                          <input type="radio" name="meta-box-radio" value="sidebar-rhs"<?php if($checkbox_value == 'sidebar-rhs'){echo 'checked =\"checked\"';} ?> /><img src="<?php echo get_template_directory_uri(); ?>/inc/admin/img/sidebar-lhs.png" width="10%" height:auto;>
                      </label>

                      <label>
                          <input type="radio" name="meta-box-radio" value="sidebar-lhs" <?php if($checkbox_value == 'sidebar-lhs'){echo 'checked =\"checked\"';} ?>/><img src="<?php echo get_template_directory_uri(); ?>/inc/admin/img/sidebar-rhs.png" width="10%" height:auto;>
                      </label>

                      <label>
                          <input type="radio" name="meta-box-radio" value="sidebar-none" <?php if($checkbox_value == 'sidebar-none'){echo 'checked =\"checked\"';} ?>/><img src="<?php echo  get_template_directory_uri(); ?>/inc/admin/img/sidebar-none.png" width="10%" height:auto;>
                      </label>
       </div>


您试图在不同的文件中使用一个变量。在大多数情况下,它将超出范围,不会在其他文件中定义

您可以尝试再次调用该函数:

<aside class="main-sidebar col <?php if(get_post_meta($object->ID, "meta-box-radio", true) == 'sidebar-lhs') {echo 'main-sidebar-reverse'; } ?> ">
    <?php dynamic_sidebar( 'sidebar1' ); ?>
</aside>

第二个代码放在哪里?Ity可能在未定义变量
$checkbox\u值的范围内。尝试
查看变量内容(如果有)。第二个代码在index.php中,第一个代码在functions.php(wordpress)中。我按照您的建议做了,但似乎缺少了其他内容。额外的类没有打印@adiogi尝试用
$post\u ID
替换
$object ID
<aside class="main-sidebar col <?php if(get_post_meta($object->ID, "meta-box-radio", true) == 'sidebar-lhs') {echo 'main-sidebar-reverse'; } ?> ">
    <?php dynamic_sidebar( 'sidebar1' ); ?>
</aside>
<?php
$checkbox_value = get_post_meta($object->ID, "meta-box-radio", true);
?>
<aside class="main-sidebar col <?php if($checkbox_value == 'sidebar-lhs') {echo 'main-sidebar-reverse'; } ?> ">
    <?php dynamic_sidebar( 'sidebar1' ); ?>
</aside>