dqmg80654
dqmg80654
2013-01-18 13:01
浏览 89
已采纳

高级自定义字段复选框

I am using advanced custom fields Checkbox feature in wordpress.

I have created a <ul> with four <li>

<ul class="post-icons">
  <li class="microphone" title="Alt text"></li>
  <li class="video" title="Alt text"></li>
  <li class="text" title="Alt text"></li>
  <li class="image" title="Alt text"></li>
</ul>

And i have created four Checkboxes in advanced custom fields. If I use this PHP in the class="(here)".

<?php echo implode(' ', get_field('field_name')); ?>

It will print the value of the Checkboxes on to the class"" but it will print all four Checkboxes values that i have created. I only would like to print the right one on the right place.

The best way would to use .active class but advanced custom fields doesn't allow multiple Checkboxes with the same value. I mean that if you Check a Checkbox on Image and text it would print .active or something wise on

<li class="image" title="Alt text"></li> and 
<li class="text" title="Alt text"></li> 

Like = <li class="image active" title="Alt text"></li> and <li class="text active" title="Alt text"></li>

I have four Checkboxes

  • Video
  • Text
  • Sound
  • Image

And four <li>

 - <li class="video"></li>
 - <li class="text"></li>
 - <li class="microphone"></li>
 - <li class="image"></li>

microphone = Sound

I would like to print .active on the right <li> class"" item. When the corresponding Checkbox is checked

I will link to the Documentation for advanced custom fields Checkbox I didn't understand a lot of how to create something what I would need for my project.

Documentation

图片转代码服务由CSDN问答提供 功能建议

我在wordpress中使用高级自定义字段复选框功能。

我创建了一个&lt; ul&gt; ,其中包含四个&lt; li&gt;

  &lt; ul class =“post-icons”&gt; 
&lt; li class =“microphone”title =“Alt text”&gt;&lt; / li&gt; 
&lt; li class =“video”title =  “Alt text”&gt;&lt; / li&gt; 
&lt; li class =“text”title =“Alt text”&gt;&lt; / li&gt; 
&lt; li class =“image”title =“Alt text”  &gt;&lt; / li&gt; 
&lt; / ul&gt; 
   
 
 

我在高级自定义字段中创建了四个复选框。 如果我在 class =“(here)”

 &lt;?php echo implode('',get_field('field_name)中使用此PHP  “));  ?&gt; 
   
 
 

它会将复选框的值打印到类“”上,但它会打印我创建的所有四个复选框值。 我只想在正确的位置打印正确的。

最好的方法是使用 .active 类,但高级自定义字段不允许多个 复选框具有相同的值。 我的意思是,如果您选中图片文字上的复选框,它会打印 .active 或其他明智的内容

 &lt; li class =“image”title =“Alt text”&gt;&lt; / li&gt; 和
&lt; li class =“text”title =“Alt text”&gt;&lt; / li&gt;  
 
Like =&lt; li class =“image active”title =“Alt text”&gt;&lt; / li&gt; 和&lt; li class =“text active”title =“Alt text”&gt;&lt; / li&gt; 
   
 
 

我有四个复选框

  • 视频
  • 文本
  • 声音
  • 图像

    四个&lt; li&gt;

       - &lt; li class =“video”&gt;&lt; / li&gt  ; 
      - &lt; li class =“text”&gt;&lt; / li&gt; 
      - &lt; li class =“microphone”&gt;&lt; / li&gt; 
      - &lt; li class =“image”&gt;  &lt; / li&gt; 
       
     
     

    麦克风=声音

    我想打印 .active 在右侧&lt; li&gt; class“”项目。 当选中相应的复选框时

    我将链接到高级自定义字段的文档复选框我不太了解如何创建我的项目所需的东西。

    文档

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • douqu2712
    douqu2712 2013-01-18 16:30
    已采纳

    It's not really clear from the Question what Fields exist.

    In the case of a Checkbox field (check PHP ternary operator):

    // If checked, the string is 'active', otherwise empty
    $image = ( get_field( 'image_field' ) ) ? 'active' : '';
    $video = ( get_field( 'video_field' ) ) ? 'active' : ''; 
    
    <li class="image <?php echo $image; ?>" title="Alt text"></li> 
    <li class="video <?php echo $video; ?>" title="Alt text"></li> 
    

    But, better yet is a Select field allowing multiple selections (check PHP in_array):
    acf select multiple

    $get_field = get_field( 'field_name' ); 
    $image = in_array( 'image', $get_field) ? 'active' : '';
    $video = in_array( 'video', $get_field) ? 'active' : '';
    
    <li class="image <?php echo $image; ?>" title="Alt text"></li> 
    <li class="video <?php echo $video; ?>" title="Alt text"></li> 
    
    点赞 评论

相关推荐